Soenneker.Compression.Zip 4.0.16

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Compression.Zip --version 4.0.16
                    
NuGet\Install-Package Soenneker.Compression.Zip -Version 4.0.16
                    
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="Soenneker.Compression.Zip" Version="4.0.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Compression.Zip" Version="4.0.16" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Compression.Zip" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Compression.Zip --version 4.0.16
                    
#r "nuget: Soenneker.Compression.Zip, 4.0.16"
                    
#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.
#:package Soenneker.Compression.Zip@4.0.16
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Compression.Zip&version=4.0.16
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Compression.Zip&version=4.0.16
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Compression.Zip

High-performance, asynchronous ZIP compression and secure extraction for .NET.

Features

  • Streams file contents asynchronously with configurable buffers
  • Atomically replaces completed archive files, preserving the previous archive on failure
  • Writes extracted files to temporary files before moving them into place
  • Rejects ZIP-slip traversal, links, duplicate destinations, and file/directory collisions
  • Supports optional entry-count, expanded-size, and compression-ratio limits for untrusted archives
  • Preserves file and directory timestamps
  • Supports paths and caller-owned streams
  • Uses only the ZIP implementation built into .NET

Installation

dotnet add package Soenneker.Compression.Zip

Quick start

using Soenneker.Compression.Zip;

var zip = new ZipUtil();

await zip.Compress("./input", "./output/archive.zip", cancellationToken: cancellationToken);
await zip.Extract("./output/archive.zip", "./restored", cancellationToken: cancellationToken);

Extraction does not overwrite existing files by default. Opt in when replacement is intended:

using Soenneker.Compression.Zip.Options;

await zip.Extract(
    "./archive.zip",
    "./destination",
    new ZipExtractionOptions { OverwriteFiles = true },
    cancellationToken);

Dependency injection

using Soenneker.Compression.Zip.Registrars;

services.AddZipUtilAsSingleton();

Then inject IZipUtil:

using Soenneker.Compression.Zip.Abstract;

public sealed class ArchiveService(IZipUtil zip)
{
    public ValueTask Backup(string source, string archive, CancellationToken cancellationToken = default) =>
        zip.Compress(source, archive, cancellationToken: cancellationToken);
}

Compression options

using System.IO.Compression;
using Soenneker.Compression.Zip.Options;

var options = new ZipCompressionOptions
{
    CompressionLevel = CompressionLevel.Fastest,
    IncludeBaseDirectory = true,
    Overwrite = true,
    PreserveTimestamps = true,
    BufferSize = 128 * 1024
};

await zip.Compress("./input", "./archive.zip", options, cancellationToken);

File-system reparse points are intentionally skipped during compression.

Extracting untrusted archives

Path and link validation is always enabled. For externally supplied archives, set limits appropriate for your workload to reduce ZIP-bomb risk:

var options = new ZipExtractionOptions
{
    MaximumEntryCount = 10_000,
    MaximumEntrySize = 256L * 1024 * 1024,
    MaximumTotalUncompressedSize = 2L * 1024 * 1024 * 1024,
    MaximumCompressionRatio = 200
};

await zip.Extract(uploadStream, "./destination", options, cancellationToken);

Caller-owned streams remain open. Archive streams used for extraction must be readable and seekable.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.24 60 9/16/2026
4.0.22 70 9/16/2026
4.0.21 77 9/16/2026
4.0.20 75 9/15/2026
4.0.19 86 9/13/2026
4.0.18 88 9/13/2026
4.0.17 80 9/13/2026
4.0.16 87 9/12/2026
4.0.15 86 9/12/2026
4.0.14 101 9/9/2026
4.0.13 100 9/9/2026
4.0.12 95 9/8/2026
4.0.11 98 9/8/2026
4.0.10 96 9/8/2026
4.0.9 96 9/8/2026
4.0.8 101 9/7/2026
4.0.7 104 9/7/2026
4.0.6 89 9/7/2026
4.0.5 97 9/7/2026
4.0.4 94 9/6/2026
Loading failed

Updated Multiple NuGet packages