Merge any number of ZIP archives

Contents
[ Hide Show ]

If you want to combine arbitrary numbers of ZIP archives into single archive read this article.

Description

Aspose.ZIP API provides  Archive class to extract and compose ZIP archives. We can extract an entry to memory without saving it into intermediate storage and pass into ZIP archive right away.

Make sure you have enough virtual memory to keep content of all entries.

Transfer an Entry

The following code example demonstrates how to extract entries from several ZIP archives and immediately put it to ZIP archive.

 1String[] archivesPaths = new String[] { "data/first.zip", "data/second.zip" };
 2Archive[] archives = new Archive[archivesPaths.length];
 3try (Archive merged = new Archive()) {
 4    for (int i = 0; i < archivesPaths.length; i++) {
 5        Archive a = new Archive(archivesPaths[i]);
 6        archives[i] = a;
 7        for (ArchiveEntry entry : a.getEntries()) {
 8            merged.createEntry(entry.getName(), entry.open());
 9        }
10    }
11
12    merged.save("merged.zip");
13
14    for (int i = 0; i < archivesPaths.length; i++) {
15        archives[i].close();
16    }
17}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.