ZIP Archives Merging in C#
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.
1 string[] archivesPaths = new string[] { "data/first.zip", "data/second.zip" };
2 Archive[] archives = new Archive[archivesPaths.Length];
3 using (var merged = new Archive())
4 {
5 for (int i = 0; i < archivesPaths.Length; i++)
6 {
7 Archive a = new Archive(archivesPaths[i]);
8 archives[i] = a;
9 foreach (ArchiveEntry entry in a.Entries)
10 merged.CreateEntry(entry.Name, entry.Open());
11 }
12
13 merged.Save("merged.zip");
14
15 for (int i = 0; i < archivesPaths.Length; i++)
16 {
17 archives[i].Dispose();
18 }
19 }