Search code examples
c#dotnetzip

Programmatically merging zip segments made by DotNetZip


I have a problem with merging zip segments which I made using DotNetZip library.

I'm zipping big file, which produces files like: abc.zip, abc.z01 and abc.z02.

using (ZipFile zip = new ZipFile())
{
    zip.AddDirectory(fullDir);
    zip.MaxOutputSegmentSize = 65536;
    zip.Save(packageFullName);

    return zip.NumberOfSegmentsForMostRecentSave;
}

In other service I want to download these files and merge them to only one zip file. I made this by simply merging theirs byte arrays. Sadly I'm getting error, that archive created by me isn't valid.

I'm not sure why my approach isn't right. I found this stack question: https://superuser.com/questions/15935/how-do-i-reassemble-a-zip-file-that-has-been-emailed-in-multiple-parts - accepted answer also produces invalid archive.

Do anybody knows how can I merge a few DotNetZip files? I don't really want to extract them in memory and pack once again, but maybe it's the only way.


Solution

  • dotnetzip can read segment zip files without problem, you can refer it's source code to take a look how it handle the segement files as one zip file, its an internal class you cannot directly use, but it may have a clue tell you how to do it:

    http://dotnetzip.codeplex.com/SourceControl/latest#Zip/ZipSegmentedStream.cs