- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个奇怪的文件,当使用 DotNetZip 压缩时,它创建了一个“无法解压缩”的存档。当我尝试使用 7zip 解压缩它时,它失败并显示 CRC failed in 'AjaxControlToolkit.dll'。文件已损坏。
当我用 7zip 手动压缩它时,它可以很好地解压缩。
有没有人遇到过 DotNetZip 无法正确压缩简单二进制文件的情况?或者我是否错误地使用了 DotNetZip?
https://dl.dropbox.com/u/65419748/AjaxControlToolkit.dll
using System.IO;
using Ionic.Zip;
namespace ConsoleApplication1
{
public class Program
{
public static void Main(string[] args)
{
var source = new FileInfo(@"C:\ZipDemo\AjaxControlToolkit.dll");
var target = new FileInfo(Path.ChangeExtension(source.FullName, "zip"));
var folder = new DirectoryInfo(Path.ChangeExtension(source.FullName, null));
if (target.Exists)
target.Delete();
if (folder.Exists)
folder.Delete(true);
using (var zip = new ZipFile(target.FullName))
{
zip.AddFile(source.FullName, string.Empty);
zip.Save();
}
using (var zip = new ZipFile(target.FullName))
zip.ExtractAll(folder.FullName);
}
}
}
抛出:
Unhandled Exception: Ionic.Zip.BadReadException: bad read of entry AjaxControlToolkit.dll from compressed archive.
at Ionic.Zip.ZipEntry._CheckRead(Int32 nbytes)
at Ionic.Zip.ZipEntry.ExtractOne(Stream output)
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
at Ionic.Zip.ZipFile._InternalExtractAll(String path, Boolean overrideExtractExistingProperty)
at Ionic.Zip.ZipFile.ExtractAll(String path)
at ConsoleApplication1.Program.Main(String[] args) in C:\ZipDemo\ConsoleApplication1\ConsoleApplication1\Program.cs:line 27
编辑:
如果我添加一个额外的字节,它工作得很好,但这不是一个可接受的解决方案。没有 + 1
会失败。
var bytes = new byte[source.Length + 1];
File.ReadAllBytes(source.FullName).CopyTo(bytes, 0);
zip.AddEntry(source.Name, bytes);
更新:
放弃并切换到 SharpZipLib,因为它不会在简单的提取上爆炸,但肯定会很高兴知道 DotNetZip 有什么问题,它有一个更好的 API。
更新2:
关于文件长度的一些问题使其爆炸,1179647 和 1179649 字节被正确压缩和解压缩。
var source = new FileInfo(@"C:\ZipDemo\foo.txt");
using (var writer = source.CreateText())
writer.Write(new string('a', 1179648));
最佳答案
您的 dll 大小为 53*128k (6954496/131072 = 53),并且 DotNetZip 中存在错误,您可以在此处阅读:https://dotnetzip.codeplex.com/workitem/14087 .只需在您的代码中使用:
zip.ParallelDeflateThreshold = -1;
我的很多文件都遇到了这个问题,现在它工作得很好 ;)
关于c# - .Extract 上的 DotNetZip BadReadException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15337186/
我有一个奇怪的文件,当使用 DotNetZip 压缩时,它创建了一个“无法解压缩”的存档。当我尝试使用 7zip 解压缩它时,它失败并显示 CRC failed in 'AjaxControlTool
我是一名优秀的程序员,十分优秀!