ZstdNet 1.5.7 (original) (raw)

Build and test NuGet NuGet Downloads

ZstdNet is a wrapper of Zstd native library for .NET languages targeting netstadard2.{0|1}. ZstdNet NuGet package includes pre-built native shared libraries for various platforms, including win, linux, osx.

The package relies on the dotnet runtime identifier resolution mechanism. For .NET Framework, the package provides a targets fallback, which requires an explicit selection of the platform — x86, x64 or ARM64).

If you need to resolve native dependency at runtime, you can use the NativeLibrary.SetDllImportResolver (see an example). And for .NET Framework — SetDllDirectory from kernel32.dll.

Provenance attestation is enabled for all artifacts in this repository including native libs, see page Attestations.

Features

Take a look on a library reference or unit tests to explore its behavior in different situations.

Zstd

Zstandard, or zstd as short version, is a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios.

Zstd is initially developed by Yann Collet and the source is available at:https://github.com/facebook/zstd

The motivation to develop of the algorithm, ways of use and its properties are explained in the blog that introduces the library:http://fastcompression.blogspot.com/2015/01/zstd-stronger-compression-algorithm.html

The benefits of the dictionary mode are described here:http://fastcompression.blogspot.ru/2016/02/compressing-small-data.html

Reference

Exceptions

The wrapper throws ZstdException in case of malformed data or an error inside libzstd. If the given destination buffer is too small, ZstdException with ZSTD_error_dstSize_tooSmallerror code is thrown away.

Check zstd_errors.h for more info.

Compressor class

Block compression implementation. Instances of this class are not thread-safe. Consider using ThreadStatic or pool of compressors for bulk processing.

Compressor();  
Compressor(CompressionOptions options);  

Options will be exposed in Options read-only field.
Note that Compressor class implements IDisposable. If you use a lot of instances of this class, it's recommended to call Dispose to avoid loading on the finalizer thread. For example:

using var compressor = new Compressor();  
var compressedData = compressor.Wrap(sourceData);  
byte[] Wrap(byte[] src);  
byte[] Wrap(ArraySegment<byte> src);  
byte[] Wrap(ReadOnlySpan<byte> src);  
int Wrap(byte[] src, byte[] dst, int offset);  
int Wrap(ArraySegment<byte> src, byte[] dst, int offset);  
int Wrap(ReadOnlySpan<byte> src, byte[] dst, int offset);  
int Wrap(ReadOnlySpan<byte> src, Span<byte> dst);  

Note that on buffers close to 2GB Wrap tries its best, but if src is uncompressible and its size is too large,ZSTD_error_dstSize_tooSmall will be thrown. Wrap method call will only be reliable for a buffer size such thatGetCompressBoundLong(size) <= 0x7FFFFFC7. Consider using streaming compression API on large data inputs.

static int GetCompressBound(int size);  
static ulong GetCompressBoundLong(ulong size);  

CompressionStream class

Implementation of streaming compression. The stream is write-only.

CompressionStream(Stream stream);  
CompressionStream(Stream stream, int bufferSize);  
CompressionStream(Stream stream, CompressionOptions options, int bufferSize = 0);  

Options:

await using var compressionStream = new CompressionStream(outputStream, zstdBufferSize);  
await inputStream.CopyToAsync(compressionStream, copyBufferSize);  

CompressionOptions class

Stores compression options and "digested" (for compression) information from a compression dictionary, if present. Instances of this class are thread-safe. They can be shared across threads to avoid performance and memory overhead.

CompressionOptions(int compressionLevel);  
CompressionOptions(byte[] dict, int compressionLevel = DefaultCompressionLevel);  
CompressionOptions(byte[] dict, IReadOnlyDictionary<ZSTD_cParameter, int> advancedParams, int compressionLevel = DefaultCompressionLevel);  

Options:

using var options = new CompressionOptions(dict, compressionLevel: 5);  
using var compressor = new Compressor(options);  
var compressedData = compressor.Wrap(sourceData);  

Decompressor class

Block decompression implementation. Instances of this class are not thread-safe. Consider using ThreadStatic or pool of decompressors for bulk processing.

new Decompressor();  
new Decompressor(DecompressionOptions options);  

Options will be exposed in Options read-only field.
Note that Decompressor class implements IDisposable. If you use a lot of instances of this class, it's recommended to call Dispose to avoid loading on the finalizer thread. For example:

using var decompressor = new Decompressor();  
var decompressedData = decompressor.Unwrap(compressedData);  
byte[] Unwrap(byte[] src, int maxDecompressedSize = int.MaxValue);  
byte[] Unwrap(ArraySegment<byte> src, int maxDecompressedSize = int.MaxValue);  
byte[] Unwrap(ReadOnlySpan<byte> src, int maxDecompressedSize = int.MaxValue);  
int Unwrap(byte[] src, byte[] dst, int offset, bool bufferSizePrecheck = true);  
int Unwrap(ArraySegment<byte> src, byte[] dst, int offset, bool bufferSizePrecheck = true);  
int Unwrap(ReadOnlySpan<byte> src, byte[] dst, int offset, bool bufferSizePrecheck = true);  
int Unwrap(ReadOnlySpan<byte> src, Span<byte> dst, bool bufferSizePrecheck = true);  

Data can be saved to a new buffer only if a field with decompressed data size is present in compressed data. You can limit size of the new buffer withmaxDecompressedSize parameter (it's necessary to do this on untrusted data).
If bufferSizePrecheck flag is set and the decompressed field length is specified, the size of the destination buffer will be checked before actual decompression.
Note that if this field is malformed (and is less than actual decompressed data size),libzstd still doesn't allow a buffer overflow to happen during decompression.

static ulong GetDecompressedSize(byte[] src);  
static ulong GetDecompressedSize(ArraySegment<byte> src);  
static ulong GetDecompressedSize(ReadOnlySpan<byte> src);  

DecompressionStream class

Implementation of streaming decompression. The stream is read-only.

DecompressionStream(Stream stream);  
DecompressionStream(Stream stream, int bufferSize);  
DecompressionStream(Stream stream, DecompressionOptions options, int bufferSize = 0);  

Options:

await using var decompressionStream = new DecompressionStream(inputStream, zstdBufferSize);  
await decompressionStream.CopyToAsync(outputStream, copyBufferSize);  

DecompressionOptions class

Stores decompression options and "digested" (for decompression) information from a compression dictionary, if present. Instances of this class are thread-safe. They can be shared across threads to avoid performance and memory overhead.

DecompressionOptions();  
DecompressionOptions(byte[] dict);  
DecompressionOptions(byte[] dict, IReadOnlyDictionary<ZSTD_dParameter, int> advancedParams);  

Options:

using var options = new DecompressionOptions(dict);  
using var decompressor = new Decompressor(options);  
var decompressedData = decompressor.Unwrap(compressedData);  

DictBuilder static class

static byte[] TrainFromBuffer(IEnumerable<byte[]> samples, int dictCapacity = DefaultDictCapacity);  

Options:

Copyright (c) 2016-2026 SKB Kontur

ZstdNet is distributed under BSD 3-Clause License.

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. net9.0 was computed. 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 was computed. 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.
.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 is compatible.
.NET Framework 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.

NuGet packages (22)

Showing the top 5 NuGet packages that depend on ZstdNet:

Package Downloads
Pulsar.Client .NET client library for Apache Pulsar 2.7M
SharpPulsar SharpPulsar is Apache Pulsar Client built using Akka.net 101.4K
EasyCompressor.Zstd An Easy-to-Use and Optimized compression library for .NET that unified several compression algorithms including LZ4, Snappy, Zstd, LZMA, Brotli, GZip, ZLib, and Deflate. This library aids in Improving Performance by Reducing Memory Usage and Bandwidth Usage. 19.3K
DevToDev.Core Devtodev Core is a dependency for all devtodev packages. It contains common functionality. 7.7K
Korucuoglu.Common Tüm projelerde kullanılabilecek genel paketleri içermektedir. 7.1K

GitHub repositories (18)

Showing the top 18 popular GitHub repositories that depend on ZstdNet:

Repository Stars
BeyondDimension/SteamTools 🛠「Watt Toolkit」是一个开源跨平台的多功能 Steam 工具箱。 25.9K
ThreeMammals/Ocelot .NET API Gateway 8.7K
morkt/GARbro Visual Novels resource browser 3.1K
toddams/RazorLight Template engine based on Microsoft's Razor parsing engine for .NET Core 1.7K
futo-org/Grayjay.Desktop Read-only mirror of Grayjay.Desktop repo for issue tracking 820
soulsmods/DSMapStudio A standalone map/level editor for Demon's Souls, Dark Souls 1/2/3, Bloodborne, Sekiro, and Elden Ring. 657
vawser/Smithbox Smithbox is a modding tool for Elden Ring, Armored Core VI, Sekiro, Dark Souls 3, Dark Souls 2, Dark Souls, Bloodborne and Demon's Souls. 645
overtools/OWLib DataTool is a program that lets you extract models, maps, and files from Overwatch. 555
UlyssesWu/FreeMote Managed Emote/PSB tool libs. 485
ZoneTree/ZoneTree ZoneTree is a persistent, high-performance, transactional, ACID-compliant ordered key-value database and LSM-tree storage engine for .NET. 474
mjebrahimi/EasyCompressor ⚡An Easy-to-Use and Optimized compression library for .NET that unified several compression algorithms including LZ4, Snappy, Zstd, LZMA, Brotli, GZip, ZLib, and Deflate. This library aids in Improving Performance by Reducing Memory Usage and Bandwidth Usage. Along with a greate Performance Benchmark between different compression algorithms. 385
modernuo/ModernUO Highly Performant & Scalable Ultima Online Server Emulator 335
fiddyschmitt/clonezilla-util Mount Clonezilla images in Windows 295
apache/pulsar-dotpulsar The official .NET client library for Apache Pulsar 270
mhwlng/streamdeck-starcitizen Elgato Stream Deck button plugin for Star Citizen 234
RedpointGames/uet UET (Unreal Engine Tool) makes building and testing Unreal Engine projects and plugins easy. It can distribute builds with BuildGraph, remotely execute automation tests on device and across multiple machines, handles fault tolerance and automatic retries and generally makes the whole experience of automating Unreal Engine a lot more pleasant. 139
vrnobody/V2RayGCon xray-core / v2ray-core 的图形配置器。Graphic configer for v2ray-core/xray-core. 139
SCToolsfactory/SCJMapper-V2 SC Joystick Mapper (.Net 4; using sharpDX wrapper) 137

Include prerelease

Include vulnerable

Include deprecated

Version Downloads Last Updated
1.5.7 42,896 2/17/2026
1.5.7-rc2 119 2/16/2026
1.5.7-rc1 122 2/16/2026
1.4.5 2,791,245 11/29/2020
1.3.3 199,856 1/6/2018
1.3.1 7,895 8/23/2017
1.2.0 3,290 5/6/2017
1.0.0 6,343 11/7/2016