Zstandard.Native 1.0.0

dotnet add package Zstandard.Native --version 1.0.0
                    
NuGet\Install-Package Zstandard.Native -Version 1.0.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="Zstandard.Native" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zstandard.Native" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Zstandard.Native" />
                    
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 Zstandard.Native --version 1.0.0
                    
#r "nuget: Zstandard.Native, 1.0.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.
#:package Zstandard.Native@1.0.0
                    
#: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=Zstandard.Native&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Zstandard.Native&version=1.0.0
                    
Install as a Cake Tool

Zstandard.Native

Ultra-fast Native AOT-safe Zstandard wrapper for .NET 8, .NET 9, and .NET 10 — zero-allocation Span<byte> APIs, source-generated [LibraryImport] P/Invoke, and hardware-accelerated buffer paths via AVX-512 / AVX10.2 and ARM64 SVE.

Install

dotnet add package Zstandard.Native

You also need a libzstd binary on the loader path. See Native runtime binaries for options (companion runtime package, bring-your-own, or system package manager).

Quick start

One-shot compress / decompress

using Zstandard.Native;

ReadOnlySpan<byte> src = File.ReadAllBytes("data.bin");

byte[] compressed = new byte[ZstdCompressor.GetCompressBound(src.Length)];
int n = ZstdCompressor.Compress(src, compressed, compressionLevel: 3);

byte[] back = new byte[src.Length];
ZstdCompressor.Decompress(compressed.AsSpan(0, n), back);

Streaming with context reuse

using var compressor = new ZstdStreamCompressor(compressionLevel: 3);
Span<byte> outBuf = stackalloc byte[ZstdStreamCompressor.RecommendedOutputSize];

foreach (var frame in frames)
{
    compressor.Reset(); // reuses ZSTD_CCtx — no allocation
    var r = compressor.Compress(frame.Span, outBuf, ZstdEndDirective.End);
    sink.Write(outBuf[..r.BytesWritten]);
}

Features

  • Zero allocations on the hot path — Span<byte>-only public API
  • Native AOT compatible — every IL2xxx/IL3xxx warning is an error in CI; no reflection, no marshalling shims
  • SafeHandle lifetime management for ZSTD_CCtx / ZSTD_DCtx — finalizer-safe even on process abort
  • Streaming with Reset() context reuse — skips ZSTD_createCCtx per frame
  • Hardware acceleration via Vector512 (AVX-512 / AVX10.2) and SVE (ARM64 variable-width) for buffer scrub operations
  • Targets libzstd ≥ 1.5.0 on win-x64, win-arm64, linux-x64, linux-arm64, osx-x64, osx-arm64

Performance highlights

Scenario Runtime Throughput Allocated
Stream compress, context reuse, 1 MiB NativeAOT 10.0 12 510 MB/s 0 B
Stream compress, context reuse, 64 KB NativeAOT 10.0 12 015 MB/s 0 B
One-shot compress vs ZstdSharp, 64 KB level 3 AOT 10.0 +37% faster 0 B vs 64 B
One-shot compress vs ZstdSharp, 1 MiB level 1 AOT 10.0 +37% faster 0 B vs 65 B

Full benchmark tables →

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.