【发布时间】:2012-10-29 23:55:54
【问题描述】:
我想提取一个 exe 文件。 exe 文件包含一些文件和文件夹。当我尝试使用 winrar 提取文件时,它会被提取,但是当我尝试使用一些示例提取 exe 文件时,我收到此错误:
GZip 标头中的幻数不正确。确保您传递的是 GZip 流。
我使用了一些示例并在 Google 上搜索了很多问题,但没有得到我的答案,而且我还使用了一些库。
我使用了这段代码,但同样的错误:
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);
}
}
}
}
【问题讨论】:
-
这是因为 .exe 文件不是有效的 .gzip 文件,但包含一个。它是一个可执行文件。 Winrar 显然能够在其中找到 .gzip(因为它可以创建这样的可执行文件,它知道它的布局并且可以读取它)。请注意,到目前为止,并非每个 .exe 文件都是自解压存档。
-
那么我该怎么办你能给我一些示例代码吗如果你能帮助我@JanDvorak 将不胜感激
-
我希望可以。我可能会为你做一些搜索,但我不能保证。
标签: c# winforms unzip compression self-extracting