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

Marcos Douglas md at delfire.net
Sun Sep 4 22:29:18 CEST 2016


Ok, it works now.

For the records, I've used the lib http://www.gocher.me/GZIP (Silvio's
tip) and the function Base64Decode from WST framework
http://svn.code.sf.net/p/lazarus-ccr/svn/wst/trunk/

For some reason the function DecodeBase64 from Synapse doesn't work.
It receives an AnsiString. Instead, the Base64Decode function receives
a TByteDynArray.

The TDataStream class doesn't matter...

So, the code below is ugly, but shows how it works now (before the refactoring).

Thank you all for the help.

=== begin ===

procedure TMainForm.Button2Click(Sender: TObject);
var
  Buf,Buf2: TMemoryStream;
  B: TByteDynArray;
begin
  Buf := TMemoryStream.Create;
  Buf2 := TMemoryStream.Create;
  try
    Buf.LoadFromFile('result.txt');
    B := Base64Decode(TDataStream.New(Buf).AsString,
[xoDecodeIgnoreIllegalChar]);
    Buf.SaveToFile('bytes.txt');
    Buf.Clear;
    Buf.WriteBuffer(Pointer(B)^, Length(B));
    if ZUncompressStream(Buf, Buf2) then
      Buf2.SaveToFile('content.txt');
  finally
    Buf.Free;
    Buf2.Free;
  end;
end;

=== end ===

Best regards,
Marcos Douglas



More information about the fpc-pascal mailing list