Skip to content

soenneker/soenneker.compression.zstandard

Soenneker.Compression.Zstandard

A utility library for Zstandard compression and decompression

Installation

dotnet add package Soenneker.Compression.Zstandard

Implementation notes

This package is a fully managed C# Zstandard implementation (no native libzstd, no external binaries).

Current codec status:

  • Strict Zstandard frame format writing/reading with checksum support.
  • Compression emits valid .zst frames using fast RAW/RLE block paths (single-threaded).
  • Decompression supports RAW/RLE frame blocks and validates frame checksums.
  • Compressed entropy-coded blocks are not implemented yet.

Usage

using Soenneker.Compression.Zstandard.Abstract;

// via DI
byte[] compressed = zstandardUtil.Compress(data);
byte[] decompressed = zstandardUtil.Decompress(compressed);

Allocation-free hot path:

int max = zstandardUtil.GetMaxCompressedLength(source.Length);
Span<byte> compressed = max <= 4096 ? stackalloc byte[max] : new byte[max];

if (zstandardUtil.TryCompress(source, compressed, out int compressedBytes))
{
    Span<byte> decompressed = new byte[source.Length];
    zstandardUtil.Decompress(compressed[..compressedBytes], decompressed);
}

About

A utility library for Zstandard compression and decompression

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages