Hi!
I've always decompressed compressed streams using the PASZLIB.
But it didn't work for this file.
I tried to use TDecompressionStream... EDecompressionError!
Finally, I tried using the ZFlate library (author: Fibonacci).
In the first case (ZFlate1 button), the function returns the correct result, the size of the decompressed data is 32768 bytes.
procedure TForm1.btnZFlate1Click(Sender: TObject);
var
bs: TBytesStream;
byOut: TBytes;
begin
bs:= TBytesStream.Create;
bs.LoadFromFile('myfile1.gz');
byOut:= zdecompress(bs.Bytes);
Memo1.Lines.Add('Size of uncompressed data: '+IntToStr(Length(byOut))); // 32768 <-- OK!
bs.Free;
end;
I noticed something strange here:
bs.size = 20086
Length(bs.Bytes = 20480
Shouldn't the sizes match?
In the second case (the ZFlate2 button), the function returns an incorrect result, the size of the decompressed data is 65536 bytes. That is, double the data!
procedure TForm1.btnZFlate2Click(Sender: TObject);
var
ms: TMemoryStream;
byIn, byOut: TBytes;
begin
ms:= TMemoryStream.Create;
ms.LoadFromFile('myfile1.gz');
SetLength(byIn, ms.Size);
ms.ReadBuffer(byIn[0], ms.Size);
byOut:= zdecompress(byIn);
Memo1.Lines.Add('Size of uncompressed data: '+IntToStr(Length(byOut))); // 65536 <-- VERY BAD !
bs.Free;
end;
What am I doing wrong?
Is there a problem with the compressed data?
I am attaching a test project.
(Window 10 64 bit + Laz 4.4 64 bit)