Article View: borland.public.cppbuilder.internet.web
Article #32Re: Zlib and Accept-Encoding: gzip, deflate
From: Colin B Maharaj
Date: Fri, 15 Feb 2008 23:25
Date: Fri, 15 Feb 2008 23:25
90 lines
3873 bytes
3873 bytes
Thanks for your help Remy, I will try this.
On another note has anyone really created a
web server (not ISS or Apache module) but
standalone web server with both SSL and
deflate support?
If not, maybe I can do an article after
I figure this out?
C++ Builder v6 SP4
Indy 9.0.15
Colin B Maharaj
Trinidad, WI
Remy Lebeau (TeamB) wrote:
> "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:
<47b61f65@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47b5dcaa$1@newsgroups.borland.com> <47b5f7df$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 Date: Fri, 15 Feb 2008 19:25:25 -0400 From: Colin B Maharaj <noreply@myhost.com> User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.web Subject: Re: Zlib and Accept-Encoding: gzip, deflate References: <47b5dcaa$1@newsgroups.borland.com> <47b5f7df$1@newsgroups.borland.com> In-Reply-To: <47b5f7df$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 080215-0, 02/15/2008), Outbound message X-Antivirus-Status: Clean NNTP-Posting-Host: 190.58.50.199 Message-ID: <47b61f65@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1203117925 190.58.50.199 (15 Feb 2008 15:25:25 -0700) Lines: 90 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail