Knapcode.MiniZip 0.21.0

dotnet add package Knapcode.MiniZip --version 0.21.0
NuGet\Install-Package Knapcode.MiniZip -Version 0.21.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Knapcode.MiniZip" Version="0.21.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Knapcode.MiniZip --version 0.21.0
#r "nuget: Knapcode.MiniZip, 0.21.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Knapcode.MiniZip as a Cake Addin
#addin nuget:?package=Knapcode.MiniZip&version=0.21.0

// Install Knapcode.MiniZip as a Cake Tool
#tool nuget:?package=Knapcode.MiniZip&version=0.21.0

MiniZip

Read the file listing of a .zip archive without downloading the whole thing.

Build

Introduction

The idea is that ZIP files have their central directory data end the end of the file. This central directory is a listing of all files in the ZIP archive. Using an HTTP HEAD request to get the file size and HTTP GET with a range request header, you can determine all of the files in a ZIP archive without downloading the whole thing.

Comcast has a 1 terabyte data limit on my line so this is a necessary measure for my efforts around NuGet package analysis.

Install

You can install this package via NuGet:

dotnet add package Knapcode.MiniZip

For more information about the package, see the package details page on NuGet.org.

Example

Take a look at the following sample code to get an idea of how this thing is used:

https://github.com/joelverhagen/MiniZip/blob/master/MiniZip.Sandbox/Program.cs

Here's a smaller example if you're into that.

var url = "https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg";

using (var httpClient = new HttpClient())
{
    var httpZipProvider = new HttpZipProvider(httpClient);

    using (var zipDirectoryReader = await httpZipProvider.GetReaderAsync(new Uri(url)))
    {
        var zipDirectory = await zipDirectoryReader.ReadAsync();

        Console.WriteLine("Top 5 ZIP entries by compressed size:");

        var entries = zipDirectory
            .Entries
            .OrderByDescending(x => x.GetCompressedSize())
            .Take(5)
            .ToList();

        for (var i = 0; i < entries.Count; i++)
        {
            Console.WriteLine($"{i + 1}. {entries[i].GetName()}");
        }
    }
}

Only a fraction of the file is downloaded to determine the metadata about the ZIP file. From my experiments this is almost always less than 1% of the total package size. Great savings! Assuming all you care about is metadata about the ZIP file, not the contained files.

In the future, perhaps I'll provide a wait to tease a single file out of the archive without downloading the whole thing...

Sample Output

The truncated output of the longer sample code looks something like this:

========================================

==> HEAD https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg

<== 200 OK
    Accept-Ranges: bytes
    Content-Length: 2066865

==> GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg
    Range: bytes=2066843-2066864

<== 206 Partial Content
    Accept-Ranges: bytes
    Content-Length: 22
    Content-Range: bytes 2066843-2066864/2066865

==> GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg
    Range: bytes=2062769-2066842

<== 206 Partial Content
    Accept-Ranges: bytes
    Content-Length: 4074
    Content-Range: bytes 2062769-2066842/2066865

Top 5 ZIP entries by compressed size:
1. lib/net45/Newtonsoft.Json.dll (243,283 bytes)
2. lib/netstandard1.3/Newtonsoft.Json.dll (238,412 bytes)
3. lib/netstandard1.0/Newtonsoft.Json.dll (232,317 bytes)
4. lib/portable-net45%2Bwin8%2Bwp8%2Bwpa81/Newtonsoft.Json.dll (232,022 bytes)
5. lib/net40/Newtonsoft.Json.dll (201,901 bytes)

========================================

...

========================================

Total ZIP files checked:    5
Total HTTP requests:        15
Total Content-Length bytes: 10,138,058
Actual downloaded bytes:    20,480
Downloaded %:               0.202%
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net451 is compatible.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Knapcode.MiniZip:

Repository Stars
NuGet/NuGetGallery
NuGet Gallery is a package repository that powers https://www.nuget.org. Use this repo for reporting NuGet.org issues.
Version Downloads Last updated
0.21.0 248 10/8/2023
0.20.0 1,909 3/29/2023
0.19.0 570 5/9/2022
0.18.0 428 5/2/2022
0.17.0 1,372 4/24/2021
0.16.0 30,185 2/22/2021
0.15.0 394 1/25/2021
0.14.0 472 12/25/2020
0.13.0 494 12/20/2020
0.12.0 497 12/20/2020
0.11.0 517 9/22/2020
0.10.0 653 7/1/2019
0.9.0 535 6/22/2019
0.8.0 604 3/1/2019
0.7.0 858 1/1/2019
0.6.0 896 5/15/2018
0.5.0 995 5/14/2018
0.4.0 986 12/30/2017
0.3.0 1,037 12/30/2017
0.2.1 1,037 12/17/2017
0.2.0 999 12/15/2017
0.1.0 4,943 12/14/2017

Retry on HTTP timeout