Re: [fpc-pascal] From deflate to gzip

2014-04-01 Thread Burdjia.com
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!
> 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] From deflate to gzip

2014-04-01 Thread silvioprog
2014-04-01 4:12 GMT-03:00 Michael Van Canneyt :
[...]

> 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)


Nice, I'll analize the possibility to implement it.

-- 
Silvio Clécio
My public projects - github.com/silvioprog
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] From deflate to gzip

2014-04-01 Thread Daniel Gaspary
On Tue, Apr 1, 2014 at 4:12 AM, Michael Van Canneyt
 wrote:
> 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)

TZipper has similar problem, you cannot write direct to the destination file.

Months a go I worked to modify the class to have a Stream writing
directly to a zip file.

A complicated change, and I don't know if worth the effort because due
to Zip format[1], I realize that only streams with support to "seek
back" would be possible.

[1] The File Header is written before the compressed stream, and it
must contain the compressed file size.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] From deflate to gzip

2014-04-01 Thread Michael Van Canneyt



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.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] From deflate to gzip

2014-03-31 Thread silvioprog
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!

-- 
Silvio Clécio
My public projects - github.com/silvioprog
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal