-
Notifications
You must be signed in to change notification settings - Fork 80
Extracting from solid archives
Alexander edited this page Jan 18, 2020
·
3 revisions
https://en.wikipedia.org/wiki/Solid_compression
Solid archives are great for better compression but not good at working with individual files. Basically, every time you need to extract single file, archiver has to go long way from beginning to this specific file.
therefore this code is extremly inefficient
using (ArchiveFile archiveFile = new ArchiveFile(@"Archive.7z"))
{
foreach (Entry entry in archiveFile.Entries)
{
// extract to file
entry.Extract(newFileName);
}
}
efficient way to work with solid archive is to extract all files alltogether
using (ArchiveFile archiveFile = new ArchiveFile(@"Archive.ARJ"))
{
archiveFile.Extract("Output"); // extract all
}
or to pass callback into Extract method. This causes archiver to make only one enumeration of files. Callback is called for every file to decide what to do: skip or extract.
using (ArchiveFile archiveFile = new ArchiveFile(@"Archive.ARJ"))
{
archiveFile.Extract( entry => {
if (mySpecialFiles.Contains(entry.FileName))
{
return Path.Combine(outputFolder, entry.FileName); // where to put this particular file
}
else
{
return null; // null means skip and do not extract
}
});
}