This is a native .NET port of Google Snappy compression/decompression library. The only implementation that is stable, fast, up to date with latest Snappy improvements, and most importantly does not depend on native Snappy binaries. Works on Windows, Linux, MacOSX, ARM and so on.
It is originally ported from the Golang implementation because Go is much easier to understand and work with comparing to C++.
The library passes golden tests from the original implementation i.e. compares that compression/decompression is fully compatible with the original implementation.
Internally, it is using array pooling and spans for efficient memory allocation and low GC pressure.
Reference the following NuGet package . You are ready to go.
To compress a buffer:
using IronSnappy;
byte[] input = File.ReadAllBytes("TestData/Mark.Twain-Tom.Sawyer.txt");
byte[] compressed = Snappy.Encode(input);
To decompress a buffer:
using IronSnappy;
byte[] input = File.ReadAllBytes("TestData/Mark.Twain-Tom.Sawyer.rawsnappy.txt")
byte[] uncompressed = Snappy.Decode(input);
Streams are fully supported. To decompress use Snappy.OpenReader(Stream)
and to compress Snappy.OpenWriter(Stream)
. Don't forget to flush 🚽 and dispose 🧻!
Contributions are more than welcome, just raise an issue and fire a PR. The code might have a few ugly bits due to the fact it was ported as is from Golang, you are welcome to make it prettier and/or faster.