A little help with ZLib deflate

Jun 7, 2010 at 11:14 AM
Edited Jun 7, 2010 at 11:17 AM

I'm trying to use theDotNetZip library to decompress a .Z (UNIX compressed) file, but so far no joy.

Here's my try-out code:


// Get the stream of the source file.
using (FileStream inFile = fiFileSrc.OpenRead())
    // decompress file.
    using (Ionic.Zlib.DeflateStream Decompress = new Ionic.Zlib.DeflateStream(inFile, CompressionMode.Decompress))
        int i = Decompress.ReadByte();


With DeflateStream I'm getting:

Ionic.Zlib.ZlibException: Bad state (invalid block type)

And with ZLibStream I'm getting:

Ionic.Zlib.ZlibException: Bad state (unknown compression method (0x1F))

as exception on the line with the ReadByte call.

I've checked and the first 2 bytes in the input file are 0x1F 0x9D which is the header for a compressed file.

I'm using DotNetZip version


What am I doing wrong?

Aug 6, 2011 at 3:13 PM

I think that .Z files use the COMPRESS compression method, which is not supported by the ZlibStream.

double-check the contents of that .Z file - is it a ZLIB-compressed stream, or a COMPRESS-compressed stream?  IF the former, you should be able to uncompress with ZlibStream.  If the latter, not.