Recent

Author Topic: How to decompress a GZip stream?  (Read 5120 times)

gabriemarcelo

  • New Member
  • *
  • Posts: 28
How to decompress a GZip stream?
« on: July 12, 2012, 09:48:45 pm »
Hi! I've spent two days trying to decompress a GZip without success, sadly. I'm getting a stream through a HTTP request using Synapse tools. The stream is GZip but I cannot decompress it using TDecompressionStream of zstream unit. Could someone share with me a code for doing this? Thanks!

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: How to decompress a GZip stream?
« Reply #1 on: July 12, 2012, 10:03:37 pm »
I believe the TDecrompressStream is just that, there is no GZIP headers etc involved.

I found this that might help ->
http://workshop.megabase.ch/en/gzfpc.html

byungho

  • Newbie
  • Posts: 2
Re: How to decompress a GZip stream?
« Reply #2 on: July 14, 2014, 03:36:29 pm »
Any solution?
I have same problem with synapse THttpsend.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8894
  • FPC developer.
Re: How to decompress a GZip stream?
« Reply #3 on: July 14, 2014, 04:22:49 pm »
Use Tgzfilestream for gzip files.  Use tdecompression stream only for zlib streams.

gzip = zlib stream prefixed with an header

byungho

  • Newbie
  • Posts: 2
Re: How to decompress a GZip stream?
« Reply #4 on: July 15, 2014, 05:32:23 am »
@marcov

Thank you. TGZFileStream works fine!
Here is my test code:
Code: [Select]
  fn := 'tt.gzip';
  gzf := TGZFileStream.create(fn, gzopenread);
  ss := TStringStream.Create('');
  try
    ss.CopyFrom(gzf, 0);
    mmLog.Lines.Add(ss.DataString);
  finally
    ss.Free;
    gzf.Free;
  end;

Is there any other way to load live stream not file ?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8894
  • FPC developer.
Re: How to decompress a GZip stream?
« Reply #5 on: July 15, 2014, 10:13:13 am »
Not that I know, since .gz is typically the fileformat, but tgzfilestream is very simple, and you could try to copy and adapt it.   

 

TinyPortal © 2005-2018