.Extract上的DotNetZip BadReadException

Ily*_*kov 21 c# dotnetzip

我有一个奇怪的文件,当用DotNetZip压缩时创建一个'ununzipable'存档.当我尝试用7zip解压缩时,它会失败,CRC failed in 'AjaxControlToolkit.dll'. File is broken.当我用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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

抛出:

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
Run Code Online (Sandbox Code Playgroud)

编辑:

如果我添加一个额外的字节它工作得很好,但它不是一个可接受的解决方案.失败了+ 1.

var bytes = new byte[source.Length + 1];
File.ReadAllBytes(source.FullName).CopyTo(bytes, 0);
zip.AddEntry(source.Name, bytes);
Run Code Online (Sandbox Code Playgroud)

更新:

放弃并切换到SharpZipLib,因为它不会在简单的提取物上爆炸,但肯定很高兴知道DotNetZip有什么问题,它有一个更好的API.

UPDATE2:

关于文件长度的一些东西让它爆炸,1179647和1179649字节被压缩并正确解压缩.

var source = new FileInfo(@"C:\ZipDemo\foo.txt");
using (var writer = source.CreateText())
    writer.Write(new string('a', 1179648));
Run Code Online (Sandbox Code Playgroud)

Xar*_*uth 17

你的dll大小是53*128k(6954496/131072 = 53),你可以在那里看到DotNetZip中的一个错误:https://dotnetzip.codeplex.com/workitem/14087 .只需在您的代码中使用:

zip.ParallelDeflateThreshold = -1;
Run Code Online (Sandbox Code Playgroud)

我对很多文件都有这个问题,它现在工作得很好;)