【发布时间】:2021-03-14 20:55:45
【问题描述】:
我正在尝试解压缩一个嵌套的 zip 文件,但我得到了一个 InvalidDataException。当我尝试在 Windows 资源管理器中解压缩相同的文件时,它会成功解压缩。为什么 Windows 资源管理器能够解压缩它而不是 .NET Core 压缩库?
我怀疑 zip 文件有问题,但如果 Windows 资源管理器能够做到,那么在 .NET Core 项目中一定可以做到。
我已尝试解压缩父 zip 文件,但会抛出 InvalidDataException 'A local file header is corrupt.'
ZipFile.ExtractToDirectory("parent.zip", outputFolder) // throws exception
我尝试打开父 zip 文件并解压缩嵌套的 zip 文件,但这也会抛出 InvalidDataException 'End of Central Directory record could not be found.'
using (var archive = ZipFile.OpenRead("parent.zip"))
{
var nestedZip = archive.GetEntry("nested.zip");
using (var stream = nestedZip.Open())
using (var nestedArchive = new Archive(stream)) // throws exception
{
nestedArchive.ExtractToDirectory(outputFolder)
}
}
【问题讨论】:
-
Windows 可能能够很好地解压缩它,但文件实际上是否完好无损?
-
@mxmissile 压缩包中有很多文件,但我打开的几个文件看起来还不错。我遇到了 zip 文件中的文件损坏的问题,但是在创建 ZipArchive 对象时它不会抛出异常,只有在提取 ZipArchiveEntry 时才会抛出异常
-
@Marshal 我看到了这个问题,但对我没有帮助
标签: c# .net-core unzip zipfile ziparchive