Hi. I am trying to use Aspose.Zip to compress some PDFs. I have attached the sample pdfs to this ticket. I have also attached the .7z files created by Aspose.Zip and by the actual program 7-Zip. The one by aspose is much larger than the one by 7-Zip. What am I doing wrong? How can I get it to compress as much as 7-Zip?
using (FileStream archiveStream = new FileStream(outputArchivePath, FileMode.CreateNew, FileAccess.Write))
{
using (SevenZipArchive archive = new SevenZipArchive())
{
foreach (string file in files)
{// Set up LZMA2-384k style compression
SevenZipEntrySettings entrySettings = null;
if (password.IsNullOrWhiteSpace() == false)
{
entrySettings = new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings(), new SevenZipAESEncryptionSettings(password));
}
else
{
entrySettings = new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings());
}
archive.CreateEntry(Path.GetFileName(file), file, false, entrySettings);
}
archive.Save(archiveStream);
}
}
7-Zip_Compressed.7z (929.6 KB)
Aspose_Compressed.7z (1.9 MB)
file-example_PDF_1MB.pdf (1017.7 KB)
file-example_PDF_1MB.pdf (1017.7 KB)
file-example_PDF_1MB.pdf (1017.7 KB)
file-example_PDF_1MB.pdf (1017.7 KB)
Hello @Robert343
this happens because 7-zip uses solid compression in your case. Since the data files are essentially the same, it benefits greatly from the high redundancy. Aspose.ZIP does not support solid compression yet — it compresses files one by one.
We plan to introduce solid compression for the 7z format in the future.
@Robert343
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): ZIPNET-1329
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Okay, I understand. Thank you, Eugene
Since July version, solid compression is implemented for non-encrypted 7z archives.
Great, thanks for implementing this. I gave it a try and I think i’m missing something though.
I added:
entrySettings.Solid = true;
This does not seem to make any difference in the output filesize. What am I missing?
Personal entry settings are ignored for solid 7z archive. You need to pass entry settings within constructor.
using (var a = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings()){Solid = true}))
{
a.CreateEntry("first", "alice29.txt");
a.CreateEntry("second", "alice29.txt");
a.Save("solid.7z");
}
using (var a = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings()){Solid = false}))
{
a.CreateEntry("first", "alice29.txt");
a.CreateEntry("second", "alice29.txt");
a.Save("nonsolid.7z");
}
Second archive appears nearly two times bigger.
Excellent Eugene. That explains why I wasn’t getting the compression. I do have a problem though, when I try to add my files I’m getting an error (‘Reading of all sources not finished yet.’). I have attached my screenshot. You can see that the code is the pretty much exactly what you did. Unless I screwed something up in my implementation. How can I solve this issue?
SourcesNotFinished.png (43.7 KB)
@Robert343
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): ZIPNET-1349
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
This is a bug. This happens in trial mode only when the total size of entries exceeds trial restrictions. We’ll fix it in the next version.
This feature works properly in the licensed version. If you haven’t license, you can request a 30 Day Temporary License for free.
Yeap, that was it. I wasn’t doing my license. When I did that it worked good. Thank you so much Eugene.
Since August version, solid compression is implemented for encrypted 7z archives.