This library provides Zstandard compression support for the Ogu.Compressions library
$ dotnet add package Ogu.Compressions.ZstdThis library provides implementation for compressing and decompressing data using Zstd.
dotnet add package Ogu.Compressions.Zstd
Registering provider:
services.AddZstdCompression();
You can customize configuration by passing action delegate:
services.AddZstdCompression(options =>
{
options.Level = CompressionLevel.Optimal;
options.BufferSize = 4096;
});
Or configure via IOptions<ZstdCompressionOptions>:
services.Configure<ZstdCompressionOptions>(options => { /* configure here */ });
| Configuration | Default Value |
|---|---|
| Level | CompressionLevel.Fastest |
| BufferSize | 81920 |
Resolving service:
you can inject the compression-specific interfaces directly:
private readonly IZstdCompression _compression;
public ZstdController(IZstdCompression compression)
{
_compression = compression;
}
Compress:
string data = "Hello, World!";
bytes[] compressedData = await _compression.CompressAsync(data);
Decompress:
bytes[] decompressedData = await _compression.DecompressAsync(compressedData);
string data = System.Text.Encoding.UTF8.GetString(decompressedData);
Links: