The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.(.exe file)
Asked Answered
O

1

7

I want to extract a exe file. The exe file contain some files and folders. When I try to extract the file using winrar it gets extracted but when I am trying to extract the exe file using some examples I am getting this error:

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

I have used some samples and googled a lot for my problem but didn't get my answer, and I have used some libraries also.

I used this code but 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);

                }
            }
        }
    }
Olimpia answered 28/10, 2012 at 4:14 Comment(3)
That's because the .exe file is not a valid .gzip file, but contains one. It is an executable file. Winrar is apparently able to find the .gzip within (because it can create such an executable, it knows its layout and can read it). Note that by far not every .exe file is a self-extracting archive.Nucleoside
so what should i do can u give me some example code please there would be a great appreciation if u can help me @JanDvorakOlimpia
I wish I could. I may do some search for you but I cannot give any guarantee.Nucleoside
C
4

That's because the .exe file is a self-extracting archive...

You should give DotNetZip a try. From the project's FAQ:

Does this library read self-extracting zip files?

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

You can install it from Nuget easily.

Compartment answered 29/10, 2012 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.