I have some data that has been passed through the DEFLATE algorithm. If I run the command perl -MCompress::Zlib -e 'undef $/; print uncompress(<>)' < deflated_data.gz
The correct output is printed. However, if I use the following code on the same data, I receive a InvalidDataException
when trying to inflate the data. Is there any implementation of INFLATE that will show me where the data is not correct?
public byte[] Inflate(byte[] inputData)
{
using (Stream input = new DeflateStream(new MemoryStream(inputData),
CompressionMode.Decompress))
{
using (MemoryStream output = new MemoryStream())
{
input.CopyTo(output);
return output.ToArray();
}
}
}
This is not a compatibility issue, but rather a format understanding issue on your part. There are three formats alluded to here: deflate (raw compressed data), zlib (deflate data wrapped in a zlib header and trailer), and gzip (deflate data wrapped in a gzip header and trailer). They are documented respectively in RFC 1951, RFC 1950, and RFC 1952.
The Compress::Zlib uncompress() function is properly documented and states that uncompress() is expecting a zlib (RFC 1950) stream. the .NET DeflateStream class is also properly documented, and is expecting a raw deflate stream (RFC 1951).
When you say that you "have some data that has been passed through the DEFLATE algorithm", what you really mean is that you have compressed to the zlib (RFC 1950) format, not the deflate format.