[fpc-pascal] From deflate to gzip

Burdjia.com burdjia at burdjia.com
Tue Apr 1 10:05:08 CEST 2014


Hello,

You can use libtar and zstream units, from the LCL.  Class
TTarArchive creates a .tar stream and TCompressionStream compress it
using gzip algorithm.  Combine them to create .tar.gz archives.

Both classes can work "on the fly" without saving information on disk.

Guillermo "Ñuño" Martínez

> Hello,
> 
> I'm using gzip from Apache to compress my static files (like HTML,
> CSS, JS etc.), and it worked fine (http://imagebin.org/303024). But,
> to compress the CGI content, I'm using deflate:
> 
> var
>   m: TMemoryStream;
> begin
>   if aeDeflate in BrookGetAcceptEncodingSet(ARequest.AcceptEncoding)
> then begin
>     m := TMemoryStream.Create;
>     try
>       with TCompressionStream.Create(clMax, m, True) do
>       try
>         Write(AResponse.Content[1], Length(AResponse.Content));
>       finally
>         Free;
>       end;
>       m.Seek(0, 0);
>       AResponse.SetCustomHeader(fieldContentEncoding, 'deflate');
>       AResponse.ContentStream := m;
>       AResponse.SendContent;
>      finally
>       m.Free;
>     end;
>   end;
> end;
> 
> Now I need to use gzip instead of deflate, like:
> 
>       AResponse.SetCustomHeader(fieldContentEncoding, 'gzip');
> 
> So, how to use zstream to (or other) to compress my content stream in
> gzip mode? I need to create a temporary gzip file (using
> TGZFileStream class) and load it after from my stream (m), or I can
> do it directly in stream?
> 
> Thank you!
> 




More information about the fpc-pascal mailing list