I've some files that were compressed using the C# DeflateStream class like this:
using (DeflateStream compressionStream = new DeflateStream(compressedFileStream, CompressionMode.Compress))
Nothing fancy, all default values. It decompresses fine using the equivalent C# DeflateStreamCode i.e.
using (DeflateStream decompressionStream = new DeflateStream(originalFileStream, CompressionMode.Decompress))
but I need to decompress this using Delphi. I've tried the zlib library (XE8, XE10.3), something along these lines:
InStream := TMemoryStream.Create;
InStream.LoadFromFile('F:\mycompressedfile.x');
DecompressionStream := TDecompressionStream.Create(InStream);
OutStream := TMemoryStream.Create;
OutStream.LoadFromStream(DecompressionStream);
OutStream.SaveToFile('F:\mydecompressedfile.x');
but keep getting 'data error' messages. How can I decompress a C# DeflateStream compressed file?
Apparently, the default settings for the Delphi deflate algorithms expect zlib headers, while the C# deflate code creates 'raw' compressed streams. Setting up the decompression stream this way (with a -ve value for WindowBits) allows Delphi to decompress the C# compressed data.
As per the official documentation: