After downloading the library, your can use the Snappy namespace:
You will gain access to low-level
SnappyCodec API that provides block-level compression.
Snappy.NET additionally contains
SnappyStream that implements streaming API for streams of unbounded size.
SnappyCodec class provides you with a pair of simple compression/uncompression methods:
public static byte Compress(byte input); public static byte Uncompress(byte input);
It cannot be simpler than that. If you would like to squeeze out the last bit of performance, there are corresponding two no-copy methods along with methods for estimating output buffer size. Explore the documentation via IntelliSense or by peeking into SnappyCodec class.
SnappyStream class is very similar to
GZipStream class in .NET Framework.
SnappyStream creates output incompatible with
SnappyCodec is for compressing fixed-size blocks,
SnappyStream is intended for unbounded streams.
SnappyStream is however compatible with other implementations of Snappy framing specification.
You can create Snappy-compressed file like this:
using (var file = File.OpenWrite("mydata.sz")) using (var compressor = new SnappyStream(file, CompressionMode.Compress)) using (var writer = new StreamWriter(compressor)) writer.WriteLine("Hello World!");
Decompression is similarly easy:
using (var file = File.OpenRead("mydata.sz")) using (var decoder = new SnappyStream(file, CompressionMode.Decompress)) using (var reader = new StreamReader(decoder)) Console.Write(reader.ReadToEnd());
If you are on .NET 4.5,
SnappyStream provides you with async variants of all I/O methods.
If you would like to do advanced stream manipulation, you can use SnappyFrame class.