开发者

DotNetZip chokes on a file

开发者 https://www.devze.com 2023-03-31 14:37 出处:网络
Would anybody have an explanation as to why DotNetZip would spin its wheels on a file? I have this file, which is copyrighted and non-distributable, that will not be zipped. I can take an earlier vers

Would anybody have an explanation as to why DotNetZip would spin its wheels on a file? I have this file, which is copyrighted and non-distributable, that will not be zipped. I can take an earlier version of the file, or a later one at that, and it will zip fine.

The zip utility shouldn't care about a version, so I'm assuming it thinks the file is corrupt somehow. How can I debug this issue? When I step through the code, the issue does not occur, but if I just let it run, it stalls at the saving of this particular file. Here's the code from the library:

ICollection<ZipEntry> c = (SortEntriesBeforeSaving) ? EntriesSorted : Entries;
foreach (ZipEntry e in开发者_如何学C c) // _entries.Values
{
    OnSaveEntry(n, e, true);
    e.Write(WriteStream);
    if (_saveOperationCanceled)
        break;

    n++;
    OnSaveEntry(n, e, false);
    if (_saveOperationCanceled)
        break;

    // Some entries can be skipped during the save.
    if (e.IncludedInMostRecentSave)
        thisSaveUsedZip64 |= e.OutputUsedZip64.Value;
}

If I put a breakpoint in that loop and let it save each file individually, then it does not choke when it sees the "bad file".

Any thoughts? I would greatly appreciate it!

EDIT 1:

Just to be clear, when I say "choke" I mean that it goes into some kind of infinite loop and will not proceed with zipping the "bad file" and moving onto the rest. Also, this is a file that is getting used by a lot of people, so it shouldn't be corrupt.

EDIT 2:

I've narrowed it down to the following:

zip.CompressionMethod = CompressionMethod.Deflate;

That compression mode causes the issue. I'm pretty sure this is a bug of some kind. The other compression method, Bzip2, is super slow. I'm not sure how I am going to get around this yet.

EDIT 3:

DotNetZip is very strange indeed. I had it fixed by adjusting the compression level to this:

zip.CompressionLevel = CompressionLevel.Default;

This fixed the problem, but then I came back after a few minutes and it would work no longer. Bzip2 still works, but like I said before, it is incredibly slow. So, I began messing around with other pieces of the ZipFile API, and I added this:

zip.CodecBufferSize = 10240000;

This makes it work now. I don't know what the bug is really?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号