Article View: borland.public.cppbuilder.internet.web
Article #31Re: Zlib and Accept-Encoding: gzip, deflate
From: Remy Lebeau (TeamB)
Date: Fri, 15 Feb 2008 20:37
Date: Fri, 15 Feb 2008 20:37
72 lines
3223 bytes
3223 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message
news:47b5dcaa$1@newsgroups.borland.com...
> This is my translation of the code....
Try this translation (there are some slight differences from yours):
const int BufferSize = 1024;
procedure zLibCompressStream(TStream *Source, TStream *Destination)
{
z_stream z_s;
int rc
// 1. Buffers for input and output
BYTE SourceBuffer [BufferSize];
BYTE DestinationBuffer[BufferSize];
// 2. Prepare the zLib data record
z_init_zstream(&z_s);
z_s.next_in = SourceBuffer;
z_s.next_out = DestinationBuffer;
z_s.avail_out = BufferSize;
// 2. Initialize the compression engine
deflateInit2(&z_s, Z_BEST_COMPRESSION, Z_DEFLATED, -15, 9,
Z_DEFAULT_STRATEGY);
// Now compress the stream
try
{
do
{
// 3. See if we got to feed more data to the compression
engine
if( (z_s.avail_in == 0) && (Source.Position < Source.Size) )
{
z_s.next_in = SourceBuffer;
z_s.avail_in = Source->Read(SourceBuffer, BufferSize);
}
// if input data completely depleted
// 4. Compress the data
rc = deflate(&z_s, (z_s.avail_in == 0) ? Z_FINISH :
Z_STREAM_END);
// 5. Check if we got compressed data to write to the
destination
if( (z_s.avail_out == 0) || (rc == Z_STREAM_END) )
{
Destination->WriteBuffer(DestinationBuffer, BufferSize -
z_s.avail_out);
z_s.avail_out = BufferSize;
z_s.next_out = DestinationBuffer;
}
// if got data available for writing
}
// 6. Repeat until buffers exhausted
while( (rc == Z_OK) && !((rc == Z_STREAM_END) && (z_s.avail_out
== BufferSize) && (z_s.avail_in == 0)) );
}
__finally
{
// 7. Clean up the engine data
deflateEnd(&z_s);
}
// try finally - clean up after engine
}
Gambit
Technical Details
Message-ID:
<47b5f7df$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeeder.dynfx.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47b5dcaa$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,84393b8885ad577b X-Google-Attributes: gidfeeec,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <47b5dcaa$1@newsgroups.borland.com> Subject: Re: Zlib and Accept-Encoding: gzip, deflate Date: Fri, 15 Feb 2008 12:37:22 -0800 Lines: 74 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <47b5f7df$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1203107807 207.178.157.90 (15 Feb 2008 12:36:47 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeeder.dynfx.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail