DotNetZip で圧縮すると、「解凍できない」アーカイブが作成される奇妙なファイルがあります。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);
        }
    }
}
スロー:
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));