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

Marcos Douglas md at delfire.net
Mon Sep 5 21:43:25 CEST 2016


On Mon, Sep 5, 2016 at 4:33 PM, Michael Van Canneyt
<michael at freepascal.org> wrote:
>
> What is the stream content ? TGZFile or simply compressed ? If it is
> TGZFile, then the header must be skipped before uncompressing data.

Simply compressed.
The example is using a file, but the real app uses streams in memory.

I can't use TBase64DecodingStream either because it not implements Seek method:

function TBase64DecodingStream.Seek(Offset: Longint; Origin: Word): Longint;
begin
  // TODO: implement Seeking in TBase64DecodingStream
  raise EStreamError.Create('Invalid stream operation');
end;

I'm trying to use like this:

=== begin ===
var
  B: TBase64DecodingStream;
  Src, Dest: TMemoryStream;
begin
  Src := TMemoryStream.Create;
  Dest := TMemoryStream.Create;
  B := TBase64DecodingStream.Create(TFileStream.Create('result.txt',fmOpenRead));
  try
    B.SourceOwner:=True;
    Src.CopyFrom(B,0);
    if ZUncompressStream(Src, Dest) then
      Dest.SaveToFile('content2.txt');
  Finally
    Src.Free;
    Dest.Free;
    B.Free;
  end;
=== end ===

So, for now I'll continue using the first solution but I would like to
use FPC sources if possible, in the future.

Regars,
Marcos Douglas



More information about the fpc-pascal mailing list