fastest way to extract .zip archive
Which is the fastest way for extracting .zip archives? Performance of my application is highly based on how 开发者_高级运维fast .zip files are extracted. I am using dotNetzip atm, but it seems that there could be more faster tools. If there is, are they safe? I've heard that QuickLZ is the fastest, but haven't tested it, also haven't found any code samples or how to use it in c#. Any help would be greatly appriciated.
Doing our own tests, 7-zip CLI (exe file) was fastest by far. It sounds crazy that a CLI application would outperform all those .NET dlls, but unfortunately it's the fact.
To be precise, I've tested SharpCompress, SharpZipLib, DotNetZip, .NET's own implementation using ZipFile and ZipArchive. All of them were running around 10-20 seconds for our test file, but 7-zip's exe process was usually finishing at 7-8 seconds.
Here is a sample code, if you decide to use 7-zip:
private static void ExtractWith7Zip(string archivePath, string extractPath)
{
var info = new ProcessStartInfo
{
FileName = @"C:\Program Files\7-Zip\7z.exe",
Arguments = $"x -y -o\"{extractPath}\" \"{archivePath}\"",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true
};
Process.Start(info)?.WaitForExit();
}
If upgrading your project to .NET 4.5 is an option, then you can use the ZipArchive
class. I wrote an article on using it, and it's dead simple. There's also ZipFile
, which I also wrote about and is even easier. I can't comment on the performance however, because I've not used third-party libraries for ZIP archives.
use DotNetZip library, you can extract all file just using ExtractAll() method :)
How large are your zip files? Perhaps you can take advantage of modern multi core processors by splitting the original file into parts, zipping each part independently and then unzipping them in your application using multithreading. The time to recombine the files in memory will be tiny compared to the unzip time.
精彩评论