[fpc-pascal] From deflate to gzip
Michael Van Canneyt
michael at freepascal.org
Tue Apr 1 09:12:39 CEST 2014
On Tue, 1 Apr 2014, silvioprog wrote:
> 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?
No, currently you need a file, unless you are willing to duplicate the tgzstream class using an in memory-approach.
(that would be a welcome addition, BTW)
Michael.
More information about the fpc-pascal
mailing list