Gzip Decompression Error

1.4k views Asked by At

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**
              }
           }
        }
2

There are 2 answers

2
Piotr Stapp On BEST ANSWER

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.

0
Mark Adler On

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