GZip标头中的幻数不正确.确保传入GZip流.(.exe文件)

Moh*_*air 7 c# compression unzip self-extracting winforms

我想提取一个exe文件.exe文件包含一些文件和文件夹.当我尝试使用winrar提取文件时,它会被提取,但是当我尝试使用一些示例提取exe文件时,我收到此错误:

GZip标头中的幻数不正确.确保传入GZip流.

我已经使用了一些样本并搜索了很多我的问题,但没有得到我的答案,我也使用了一些库.

我使用此代码但错误相同:

    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);

                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

Yan*_*eau 4

那是因为该.exe文件是自解压存档......

您应该尝试一下DotNetZip。来自项目的常见问题解答:

该库是否读取自解压 zip 文件?

是的。DotNetZip 可以读取 WinZip 生成的自解压存档 (SFX),WinZip 可以读取 DotNetZip 生成的 SFX 文件。

您可以轻松地从 Nuget 安装它