Skip to content
A Zstandard wrapper for .Net
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Zstandard.Net.Benchmark version 1.1.7 Mar 16, 2019
Zstandard.Net.Sandbox Use shared ArrayPool for internal buffer Feb 17, 2018
Zstandard.Net.Tests
Zstandard.Net version 1.1.7 Mar 16, 2019
.gitattributes
.gitignore Initial commit Nov 6, 2017
LICENSE Update LICENSE Nov 6, 2017
README.md Update README.md Nov 12, 2017
Zstandard.Net.sln Added pool for internal buffer to reduce garbage collections Feb 17, 2018

README.md

Zstandard.net

A Zstandard wrapper for .Net

Zstandard is a real-time compression algorithm, providing high compression ratios. It offers a very wide range of compression / speed trade-off, while being backed by a very fast decoder. It also offers a special mode for small data, called dictionary compression, and can create dictionaries from any sample set. Zstandard library is provided as open source software using a BSD license.

http://facebook.github.io/zstd/

Example

byte[] input = GetTestData();
byte[] compressed = null;
byte[] output = null;

// load a dictionary that is trained for the data (optional).
var dictionary = new ZstandardDictionary("loremipsum.zdict");

// compress
using (var memoryStream = new MemoryStream())
using (var compressionStream = new ZstandardStream(memoryStream, CompressionMode.Compress))
{
	compressionStream.CompressionLevel = 11;               // optional!!
	compressionStream.CompressionDictionary = dictionary;  // optional!!
	compressionStream.Write(input, 0, input.Length);
	compressionStream.Close();
	compressed = memoryStream.ToArray();
}

// decompress
using (var memoryStream = new MemoryStream(compressed))
using (var compressionStream = new ZstandardStream(memoryStream, CompressionMode.Decompress))
using (var temp = new MemoryStream())
{
	compressionStream.CompressionDictionary = dictionary;  // optional!!
	compressionStream.CopyTo(temp);
	output = temp.ToArray();
}

// test output
if (output.SequenceEqual(input) == false)
{
	throw new Exception("Output is different from input!");
}

NuGet

Download the library from NuGet:

https://www.nuget.org/packages/Zstandard.Net/

You can’t perform that action at this time.