Article View: borland.public.cppbuilder.nativeapi
Article #5469Re: Compress/uncompress a Buffer
From: Andrue Cope [TeamB]
Date: Thu, 18 Aug 2005 15:06
Date: Thu, 18 Aug 2005 15:06
51 lines
2453 bytes
2453 bytes
sam wrote:
> I am looking for a library that allow Compress/Uncompress a Buffer.
> I have make several search a have a look to ZLib library.
> But it is very hard to use it, and I have not found any sample for
> BCB.
Why is it hard to use? It doesn't even use callbacks.
You populate a structure that contains pointers to source and
destination and counters for each. Then you call a function and look at
what the function returned and/or what the pointers are pointing to.
Example code:
// buffer is a pointer to compressed data.
// ChunkSize is the number of bytes pointed to by buffer.
// Output buffer needs to be big enough of course but that's easy
// enough to ensure. Either assume a maximum compression window
// or have the compressed data prefixed by an output length
// field.
MyZLibStream.next_in=buffer;
MyZLibStream.avail_in=ChunkSize;
MyZLibStream.next_out=MyLastCompChunkData.get();
MyZLibStream.avail_out=ZLIBCHUNK_SIZE+4;
memset( MyLastCompChunkData.get(), 0, ZLIBCHUNK_SIZE+4 );
if( inflateInit( &MyZLibStream )==Z_OK )
{
int err=inflate( &MyZLibStream,
Z_FINISH );
if( err!=Z_STREAM_END )
{ // D'oh!
inflateEnd( &MyZLibStream );
return ?* ERROR *?;
}
}
inflateEnd( &MyZLibStream );
// MyLastCompChunkData.get() is start of uncompressed data.
// ..have a nice day :)
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<4304a3dd@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4304a1d6@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,68b90959c01bbcf3 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address> Subject: Re: Compress/uncompress a Buffer Newsgroups: borland.public.cppbuilder.nativeapi References: <4304a1d6@newsgroups.borland.com> Date: Thu, 18 Aug 2005 16:06:18 +0100 User-Agent: XanaNews/1.17.5.9 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <4304a3dd@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1124377565 217.207.223.34 (18 Aug 2005 08:06:05 -0700) Lines: 51 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail