🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #30

Zlib and Accept-Encoding: gzip, deflate

#30
From: Colin B Maharaj
Date: Fri, 15 Feb 2008 18:40
75 lines
3006 bytes
Hi all, has anyone has any luck in
using the ZLIB Library to do compression
of html going out of a web server for
html v1.1 compliance?

USING C++ Builder! I heard that there
was a library


I tried a lot of things but no luck.
I was able to even link and use this

http://dn.codegear.com/article/20299

but keep getting access violation the
moment I call deflateInit2

This is my translation of the code....

void zLibCompressStream(TStream * Source, TStream * Destination)
{
   int BufferSize=65536;//1024;
   char *SourceBuffer = new char [BufferSize];
   char *DestinationBuffer = new char [BufferSize];
   int rc;
   z_stream z_s;

   z_init_zstream(z_s);
   z_s.next_in = SourceBuffer;
   z_s.next_out = DestinationBuffer;
   z_s.avail_out = BufferSize;

   deflateInit2(&z_s, Z_BEST_COMPRESSION, Z_DEFLATED, -15, 9, 
Z_DEFAULT_STRATEGY );

    // Now compress the stream
   try
   {
     bool EndCond;
     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


       if ( z_s.avail_in == 0 )   rc = deflate( &z_s, Z_FINISH );
       else                       rc = deflate( &z_s, 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
        EndCond = ( rc != Z_OK ) || ( ( rc == Z_STREAM_END ) &&
                    ( z_s.avail_out == BufferSize ) && ( z_s.avail_in == 
0 ) );
     }
     while (!EndCond);
   }

   catch(...)
   {

   }
   delete SourceBuffer;
   delete DestinationBuffer;
   deflateEnd(&z_s);
}
Technical Details
Message-ID: <47b5dcaa$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!ucberkeley!news-hog.berkeley.edu!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,84393b8885ad577b,start
X-Google-Attributes: gidfeeec,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 15 Feb 2008 14:40:42 -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: Zlib and Accept-Encoding: gzip, deflate
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Antivirus: avast! (VPS 080214-0, 02/14/2008), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 190.58.50.199
Message-ID: <47b5dcaa$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1203100842 190.58.50.199 (15 Feb 2008 10:40:42 -0700)
Lines: 75
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!ucberkeley!news-hog.berkeley.edu!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail