Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 723
andree Avatar asked Apr 13 '11 10:04

andree


2 Answers

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();
    }
like image 142
Mladen B. Avatar answered Sep 17 '22 06:09

Mladen B.


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.

like image 43
David Anderson Avatar answered Sep 17 '22 06:09

David Anderson