9

I need to create spanned (multi-volume) zip files using .Net, but I have been unable to find a library that enables me to do it.

Spanned zip is a zip compressed file that is split among a number of files, which usually have extensions like .z00, .z01, and so on.

The library would have to be open-source or free, because I'm gonna use it for a open source project.

(it's a duplicate to this question, but there are no answers there and I'm not going for ASP specific anyway)

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Bruno Brant
  • 8,226
  • 7
  • 45
  • 90
  • Years later, but just to clarify this question is about split archives. Spanned zip archives are something else entirely - single ZIP archives split across multiple logical volumes (generally designed around floppy disks). The difference is that a split ZIP archive uses the ".z00 - .z(n - 1)" naming whereas in a spanned archive all of the files share the same name (with the same ".zip" extension). – monkey0506 Feb 16 '15 at 09:34
  • According to our [on-topic](https://stackoverflow.com/help/on-topic) guidance, "**Some questions are still off-topic, even if they fit into one of the categories listed above:**...Questions asking us to *recommend or find a book, tool, software library, tutorial or other off-site resource* are off-topic..." – Robert Columbia Nov 28 '18 at 14:44

3 Answers3

30

DotNetZip example:

int segmentsCreated ;
using (ZipFile zip = new ZipFile())
{
  zip.UseUnicode= true;  // utf-8
  zip.AddDirectory(@"MyDocuments\ProjectX");
  zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G") ;
  zip.MaxOutputSegmentSize = 100*1024 ; // 100k segments
  zip.Save("MyFiles.zip");

  segmentsCreated = zip.NumberOfSegmentsForMostRecentSave ;
}

if segmentsCreated comes back as 5, then you have the following files, each not more than 100kb in size.

  • MyFiles.zip
  • MyFiles.z01
  • MyFiles.z02
  • MyFiles.z03
  • MyFiles.z04

Edited To Note: DotNetZip used to live at Codeplex. Codeplex has been shut down. The old archive is still [available at Codeplex][1]. It looks like the code has migrated to Github:


Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135
  • nice code but do not understand this line `zip.MaxOutputSegmentSize = 100*1024` how does it mean 100 kb ? i guess u try to say 1024Byte means 1KB and 1KB*100 means 100 KB.....am i right ? – Mou Apr 05 '15 at 17:53
  • Hey guys ! Once the folder is splitted into multiple segments, how do you put them back together to unzip them and have the initial content ? In your example, how do you read the 5 zip files (MyFiles.zip, MyFiles.z01, MyFiles.z02, MyFiles.Z03 and MyFiles.z04) to get the initial directory ? – SylvainB2347 Feb 02 '22 at 15:49
18

DotNetZip allows you to do this. From their documentation:

The library supports zip passwords, Unicode, ZIP64, stream input and output, AES encryption, multiple compression levels, self-extracting archives, spanned archives, and more.

Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • 1
    dotNetZip has a max number of spanned file = 99.if you want to make a 15mb files (to send to email) and the zipped stuff are > ~ 1.5GB you are out of luck. – EKanadily Mar 23 '14 at 09:12
  • 1
    It is true that DotNetZip has a maximum file (segment) count of 99 for split archives, though this seems to be entirely arbitrary. The earliest revision I can find (Wikipedia) that specifies a limit is 6.3.0 (2006), which matches 6.3.4 (2014) in a ~4 billion file limit (http://goo.gl/vh4Sp5 - Section 8.5.1). However, since the library is open-source, you could at the very least create a custom modification of it. With a minimum file size of 64K (per ZIP specification), you could have roughly 256 TB in one split ZIP archive without going over the file limit. – monkey0506 Feb 16 '15 at 09:27
  • There was a pull request merged in 2014 that removed the 99 file limit. I can confirm that there is no more file limit – adrotter Feb 09 '21 at 19:58
2

Take a look at the SevenZipSharp library. It supports multivolumes archives.

Icemanind
  • 47,519
  • 50
  • 171
  • 296
platon
  • 5,310
  • 1
  • 22
  • 24