Parallel composition of ZIP Archives

Overview

Aspose.ZIP API provides an ability to compose ZIP archives. Because the entries of such archive can be compressed independently, it is possible to parallelize archive creation to some degree.

ZIP multithreaded: explanation

Use ParallelOptions to indicate that archive needs to be prepared with several CPU cores.

Setting ParallelCompressInMemory indicates the strategy we choose to multitask. Here are three options:

We encourage you to play with different modes of parallel compression on your typical data to determine what is the best settings in your case.

How to Create ZIP Archive with Parallel Compression in C# Sample

Steps: Create ZIP Archive with Parallel Compression in C#

  1. Open a file stream (FileStream) in FileMode.Create to create a new ZIP file (archive.zip).
  2. Initialize a new Archive object for managing ZIP entries.
  3. Use the CreateEntry method to add multiple entries, such as “first.bin” and “last.bin”, using File.OpenRead to read from the source files (data1.bin and dataN.bin).
  4. Set up ArchiveSaveOptions with ParallelOptions, where ParallelCompressInMemory is set to ParallelCompressionMode.Always, enabling parallel compression for faster archiving.
  5. Save the archive with the specified options using the Save method.
 1    using (FileStream zipFile = File.Open("archive.zip", FileMode.Create))
 2    {
 3        using (Archive archive = new Archive())
 4        {
 5            archive.CreateEntry("first.bin", File.OpenRead("data1.bin"));
 6            ...
 7            archive.CreateEntry("last.bin", File.OpenRead("dataN.bin"));
 8            archive.Save(zipFile, new ArchiveSaveOptions()
 9            {
10                ParallelOptions = new ParallelOptions() 
11                { ParallelCompressInMemory = ParallelCompressionMode.Always }
12            });
13        }
14    }
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.