1

I'm trying to decompress a byte array. Because I want to extract a .png file from a zip.

I tried this:

var compressedData = ZlibStream.UncompressBuffer(cByteArray);

var uncompressedData = ZlibStream.CompressBuffer(compressedData);   

using(FileStream fs = new FileStream(@"F:\picture.png", FileMode.Create)){

fs.Write(uncompressedData, 0, uncompressedData);
}

But got the following error: Bad state (unknown compression method (0x5C))

So can anyone help me out on how to get the file from the data. The compressed data is from a zip file entry. So the header is excluded.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user2911090
  • 15
  • 1
  • 7

1 Answers1

2

Use DeflateStream, not ZlibStream. The former processes raw deflate data as wrapped in zip files. The latter processes zlib streams, which is deflate data with a zlib wrapper.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • I tried with System.IO.Compression.DeflateStream but I keep getting this error: "Found invalid data while decoding." – user2911090 Oct 27 '13 at 21:14
  • Then you did not extract the deflate data correctly from the zip file. You could consider using the `ZipArchive` class instead, which will handle that for you. – Mark Adler Oct 27 '13 at 23:46
  • It works great now! Turned out I had the layout wrong I read the extralength after compressed data instead of in front. Thanks – user2911090 Oct 28 '13 at 07:00