0

I want to decompress a zip file.

The code that I used is so simple.

I could not understand why I' m getting this error;

The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.

        public static void Decompress(Stream fileToDecompress)
           {
           using (FileStream decompressedFileStream = File.Create("BinaryTest"))
           {
              using (GZipStream decompressionStream = new GZipStream(fileToDecompress, CompressionMode.Decompress))
              {
                decompressionStream.CopyTo(decompressedFileStream);   **Error**
              }
           }
        }
Anil Kocabiyik
  • 1,178
  • 6
  • 17
  • 47

2 Answers2

1

gzip is not zip. zip is not gzip. You can use the ZipFile class or DotNetZip to extract a zip file.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
0

Did you check if fileToDecompress is proper GZipStream? You can copy it locally to file and check if it is valid. The error show clean that data in the stream is not valid.

Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • I got fileToDecompress = _assembly.GetManifestResourceStream("path"); Should I convert the stream to GZipStream? – Anil Kocabiyik Nov 27 '14 at 14:08
  • So just copy this stream into file and check what it is inside. Instead of GZipStream use FileStream for testing. I'm 100% sure that this stream is not GZip – Piotr Stapp Nov 27 '14 at 14:09