The magic number in the GZip header is incorrect. Make sure you stream the GZip stream. (.exe file)

I want to extract an exe file. The exe file contains some files and folders. When I try to extract the file using winrar, it is extracted, but when I try to extract the exe file using some examples, I get this error:

The magic number in the GZip header is incorrect. Make sure you stream the GZip stream.

I used some samples and searched a lot for my problem, but did not get an answer, and I also used some libraries.

I used this code, but the same error:

public static void Decompress(FileInfo fi) { // Get the stream of the source file. using (FileStream inFile = fi.OpenRead()) { // Get original file extension, for example // "doc" from report.doc.gz. string curFile = fi.FullName; string origName = curFile.Remove(curFile.Length - fi.Extension.Length); //Create the decompressed file. using (FileStream outFile = File.Create(origName)) { using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress)) { // Copy the decompression stream // into the output file. Decompress.CopyTo(outFile); Console.WriteLine("Decompressed: {0}", fi.Name); } } } } 
+6
source share
1 answer

This is because the .exe is a self-extracting archive ...

You must give DotNetZip a try. From the FAQ project:

Does this library read self-extracting zip files?

Yes. DotNetZip can read self-extracting archives (SFX) created by WinZip, and WinZip can read SFX files created by DotNetZip.

You can easily install it from Nuget .

+4
source

All Articles