🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
4 messages
4 total messages Started by Colin B Maharaj Fri, 15 Feb 2008 18:40
Zlib and Accept-Encoding: gzip, deflate
#30
Author: 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);
}
Re: Zlib and Accept-Encoding: gzip, deflate
#31
Author: Remy Lebeau (TeamB)
Date: Fri, 15 Feb 2008 20:37
72 lines
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
Re: Zlib and Accept-Encoding: gzip, deflate
#32
Author: Colin B Maharaj
Date: Fri, 15 Feb 2008 23:25
90 lines
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
> 
> 
Re: Zlib and Accept-Encoding: gzip, deflate
#33
Author: Colin B Maharaj
Date: Sat, 16 Feb 2008 02:00
98 lines
4148 bytes
OK ,so there is an idServerCompressionIntercept
component, this should do what I seek.
Thanks Remy for your time and effort.


Colin B Maharaj wrote:
> 
> 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
>>
>>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads