[fpc-pascal] GZip - Stream decompress only in memory

Marcos Douglas md at delfire.net
Sun Sep 4 19:17:29 CEST 2016


On Sun, Sep 4, 2016 at 1:37 PM, Ewald <ewald at yellowcouch.org> wrote:
> On 04/09/16 18:08, Marcos Douglas wrote:
>> Hi,
>>
>> I have streams compressed using GZip. I get these streams from WebServices.
>> So, how can I decompress these streams only in memory?
>
> Perhaps have a look at zlibar. The main, and only, unit contains these
> functions:
>
> function CompressStream(InStream: TStream; OutStream: TStream): Integer;
> function ExtractStream(InStream: TStream; OutStream: TStream): Integer;
>
> I think this is what you are looking for. I don't know about file
> headers. At least it would form a good starting point.
>
> Good luck!

Hi and thanks.

I think you're talking about this lib, right?
http://wiki.freepascal.org/Zlibar

I installed and tried, but didn't work.

See my code:

=== begin ===

procedure TMainForm.Button2Click(Sender: TObject);
var
  Buf,Buf2: TMemoryStream;
begin
  Buf := TMemoryStream.Create;
  Buf2 := TMemoryStream.Create;
  try
    Buf.LoadFromFile('data.txt');
    showmessage(inttostr(ExtractStream(Buf, Buf2))); //<< result is 0, ie, OK
    Buf2.SaveToFile('result.txt');
  finally
    Buf.Free;
    Buf2.Free;
  end;
end;

=== end ===

There is no error, but Buf2 is empty.

Regards,
Marcos Douglas



More information about the fpc-pascal mailing list