Anil Kocabiyik
Anil Kocabiyik

Reputation: 1188

Gzip Decompression Error

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

Upvotes: 0

Views: 1679

Answers (2)

Mark Adler
Mark Adler

Reputation: 112502

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

Upvotes: 1

Piotr Stapp
Piotr Stapp

Reputation: 19828

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.

Upvotes: 0

Related Questions