Incrementally Add Files to a ZIP Archive in .NET and Java


The Zip component supports creating archives incrementally so you can add files as they become available instead of waiting for all files before compressing. This reduces latency and can improve throughput in workflows where files are produced or received over time.

This feature is available in the Java and .NET editions. To enable incremental archive creation, set CloseArchiveAfterCompress to false. When false, each Compress call writes the current Files collection into the archive but does not close it, allowing you to add more files and call Compress again. After all files are added, set CloseArchiveAfterCompress back to true and call Compress once more to finalize and close the archive. For instance:

zip.Config("CloseArchiveAfterCompress=false");

//Add one file
zip.Files.Add(new ZIPFile("..\\..\\files\\test.txt"));
zip.Compress();

//Add another file
zip.Files.Clear();
zip.Files.Add(new ZIPFile("..\\..\\files\\test2.txt"));
zip.Compress();

//Ready to finish creating the archive
zip.Config("CloseArchiveAfterCompress=true");

zip.Files.Clear();
zip.Compress(); //Must be called to finish archive creation

We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.