[fpc-pascal] GZip - Stream decompress only in memory
Marcos Douglas
md at delfire.net
Mon Sep 5 22:32:15 CEST 2016
On Mon, Sep 5, 2016 at 4:43 PM, Marcos Douglas <md at delfire.net> wrote:
> 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;
Ok, now I understand how TBase64DecodingStream works.
The code below is working.
=== begin ===
var
Decoder: TBase64DecodingStream;
F: TFileStream;
Src, Dest: TMemoryStream;
begin
F := TFileStream.Create('result.txt', fmOpenRead);
Decoder := TBase64DecodingStream.Create(F);
Src := TMemoryStream.Create;
Dest := TMemoryStream.Create;
try
Src.CopyFrom(Decoder, Decoder.Size);
if ZUncompressStream(Src, Dest) then
Dest.SaveToFile('content.txt');
Finally
F.Free;
Src.Free;
Dest.Free;
Decoder.Free;
end;
end;
=== end ===
Regards,
Marcos Dougas
More information about the fpc-pascal
mailing list