Converting ZIP to 7z
If you want to convert the ZIP archive to 7z read this article.
Aspose.Zip now allows composing 7z archive with LZMA, LZMA2, PPMd and BZip2 compression algorithms.
Convertation
Aspose.ZIP API provides the SevenZipArchive class to work with 7z archives. We can extract an entry to memory without saving it into intermediate storage and pass it into the 7z archive right away.
Make sure you have enough virtual memory to keep the content of all entries.
Transfer an Entry
The following code example demonstrates how to extract entries from the ZIP archive and immediately put them to the 7z archive. 7z entries will be compressed with the LZMA2 method regardless of what algorithm they had in the source archive. Entries that are directories are skipped, but their files are added respecting relative paths.
1try (Archive source = new Archive("source.zip")) {
2 try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings()))) {
3 for (ArchiveEntry entry : source.getEntries()) {
4 if (!entry.isDirectory()) {
5 try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
6 entry.extract(out);
7 try (ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())) {
8 archive.createEntry(entry.getName(), in);
9 }
10 }
11 }
12 }
13 archive.save("result.7z");
14 }
15} catch (IOException ex) {
16}