I need to compress data in a “raw deflate” manner, with Windowbits set to -15. Files containing compressed data have been compressed that way by an external party, which gets decompressed also by an external tool.
To properly decompress this data I have to use windowbits -15. This code works:
procedure DeCompressStreamBits(Src: TMemoryStream; bits: Integer);
Var z: TZDeCompressionStream;
mem: TMemoryStream;
begin
Src.Seek32(0, soBeginning);
z := TZDecompressionStream.Create(Src, bits);
mem := TMemoryStream.Create;
z.Seek32(0, soBeginning);
mem.CopyFrom(z, z.Size);
mem.Seek32(0, soBeginning);
Src.Clear;
Src.SetSize(mem.Size);
Src.Write(mem.Memory^, mem.Size);
mem.Free;
z.Free;
end;
The problem: I need to generate similarly compressed files for that tool to decompress them; what is the correct way to do that in this case? the following code results in the destination stream being empty.
procedure CompressStreamBits(Src: TMemoryStream; bits: Integer);
Var z: TZCompressionStream;
mem: TMemoryStream;
begin
mem := TMemoryStream.Create;
z := TZCompressionStream.Create(mem, zcFastest, bits);
Src.Seek32(0, soBeginning);
z.CopyFrom(Src, Src.Size);
mem.Seek32(0, soBeginning);
Src.Clear;
Src.SetSize(mem.Size);
Src.Write(mem.Memory^, mem.Size);
mem.Free;
z.Free;
end;