https://github.com/soenneker/soenneker.compression.zstandard
A utility library for Zstandard compression and decompression
https://github.com/soenneker/soenneker.compression.zstandard
compressing compression csharp dotnet util zstandard zstandardutil zstd
Last synced: about 2 months ago
JSON representation
A utility library for Zstandard compression and decompression
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.compression.zstandard
- Owner: soenneker
- License: mit
- Created: 2026-03-02T01:08:48.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-04-21T02:51:58.000Z (2 months ago)
- Last Synced: 2026-04-21T04:41:09.193Z (2 months ago)
- Topics: compressing, compression, csharp, dotnet, util, zstandard, zstandardutil, zstd
- Language: C#
- Homepage: https://soenneker.com
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/soenneker.compression.zstandard/)
[](https://github.com/soenneker/soenneker.compression.zstandard/actions/workflows/publish-package.yml)
[](https://www.nuget.org/packages/soenneker.compression.zstandard/)
[](https://github.com/soenneker/soenneker.compression.zstandard/actions/workflows/codeql.yml)
#  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
```csharp
using Soenneker.Compression.Zstandard.Abstract;
// via DI
byte[] compressed = zstandardUtil.Compress(data);
byte[] decompressed = zstandardUtil.Decompress(compressed);
```
Allocation-free hot path:
```csharp
int max = zstandardUtil.GetMaxCompressedLength(source.Length);
Span compressed = max <= 4096 ? stackalloc byte[max] : new byte[max];
if (zstandardUtil.TryCompress(source, compressed, out int compressedBytes))
{
Span decompressed = new byte[source.Length];
zstandardUtil.Decompress(compressed[..compressedBytes], decompressed);
}
```