GitHub - skbkontur/ZstdNet: Zstd wrapper for .NET (original) (raw)

Build and test NuGet NuGet Downloads Reproducible Build Provenance Attestation

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. For win, the static VC runtime is used.

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.

CompressionStream class

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

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.

Decompressor class

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

DecompressionStream class

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

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.

DictBuilder static class

Wrapper Authors

Copyright (c) 2016-2026 SKB Kontur

ZstdNet is distributed under BSD 3-Clause License.