fastest way to extract .zip archive

12,092

Solution 1

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();
    }

Solution 2

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.

Share:
12,092
andree
Author by

andree

Updated on July 22, 2022

Comments

  • andree
    andree almost 2 years

    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.

    • Cheeso
      Cheeso about 13 years
      Regarding Performance of my application is highly based on how fast .zip files are extracted - if you describe further, we might have some suggestions on how to optimize. Have you tried "fastest compression" levels in DotNetZip? If you have control over the compression side, you may be able to use less-general compression approaches that are faster to decompress also, if your data is constrained in some way.
    • andree
      andree about 13 years
      Too bad I have to extract files that have been compressed by some other soft, so I can't choose lower compression levels.
    • andree
      andree about 13 years
      In my application, about half of time spent by main method running, is used by extracting .zip archives, so improving extract time would be a great performance upgrade. After extracting, I need to access some metadata on theese files, and, after that, move them to some other locations based on metadata.
    • RobV
      RobV about 13 years
      Does your main method need/could do anything else while ZIP files are extracting? May be worth moving the extraction to a background worker, thread or async call to boost performance if that is an option
    • andree
      andree about 13 years
      Extraction method is already in backgroundworker, but since application needs extracted data to perform next function, I still need for it to wait, while data are being extracted.
    • Alois Kraus
      Alois Kraus over 11 years
      You could extract the first 1KB to read the header and then extract directly to the final location. That should be much faster as well.
  • andree
    andree about 13 years
    Zip files are aroung 500 MB to 1.5 GB. So you think I should create 2 zip files from original, and then extract each one of them?
  • Christopher King
    Christopher King over 7 years
    Blog links are dead.
  • Mladen B.
    Mladen B. about 4 years
    If you already have a zip file to begin with, than this answer makes no sense, since you can't control how the users are going to create their zip files. If you decide to "split the original file into parts", you'll still need to extract the original file and only after that you'll be able to create several partial zip files, which is obviously waste of time.