GZ Deflated Data - decompression lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- WallE · 2012-12-27 06:16 How should I decompress a GZ Deflated stream returned by  HTTPSend object . I searched the forum but I could not find the right answers. ---------------------------------------------------------------------- BigChimp · 2012-12-27 07:51 You can also search the wiki and the FPC documentation. No idea, but I've seen posts discussing this. Also, depending on the network library you use, that library may have support for deflate (I remember a thread on the Synapse forum on this). Good luck.... if you find an answer please add it to the relevant networking article on the wiki (e.g. the synapse HTTP download example) so others can use it. ---------------------------------------------------------------------- WallE · 2012-12-27 08:52 I searched the forum and wiki and found several examples of decompression (.gz file decompression ) . They work in case of file, but I was unable to use them for streams(TMemorystream or others like it) . ---------------------------------------------------------------------- marcov · 2012-12-27 14:04 Tdecompressionstream in unit zstream ---------------------------------------------------------------------- WallE · 2012-12-31 06:08 Quote from: marcov on December 27, 2012, 03:04:28 pmTdecompressionstream in unit zstream yes I saw that , there is an example for file(TGZFileStream), but I could not find any example for  TMemoryStream and I tried modifying that example to make It work with stream , still stuck ---------------------------------------------------------------------- WallE · 2013-01-15 06:39 Got it working using ZlibEx - this helped -> http://www.mombu.com/programming/delphi/t-decompress-gz-files-with- zlib-unit-757071.html but still need improvement (suggest if you can) Code: [Select]program simpledemo; {$mode objfpc}{$H+} uses   Classes,SysUtils,fphttpclient,HTTPSend,ZLibEx; Var  z:TZDecompressionStream  ;  pBuffer:pChar;  bytesRead: Integer;  apiurl:string;  B:string;  HTTP:THTTPSend;  bufferSize:Integer; begin   apiurl:='http://127.0.0.1/test-file.json.gz';   HTTP := THTTPSend.Create;   HTTP.Headers.Add('Accept-Encoding:gzip,deflate');   HTTP.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1';   HTTP.HTTPMethod('GET', apiurl);   bufferSize := 500000;   GetMem(pBuffer, bufferSize);   z := TZDecompressionStream.Create(HTTP.Document,12+32);   bytesRead:=z.Read(pBuffer^, bufferSize);   z.Free();   WriteLn (bytesRead, ' bytes read.');   B:=string(pBuffer);   WriteLn (B);   FreeMem(pBuffer, bufferSize);   WriteLn('Done.');   ReadLn;   HTTP.Free;   ReadLn; end.