![]() |
VOOZH | about |
dotnet add package Snappier --version 1.3.1
NuGet\Install-Package Snappier -Version 1.3.1
<PackageReference Include="Snappier" Version="1.3.1" />
<PackageVersion Include="Snappier" Version="1.3.1" />Directory.Packages.props
<PackageReference Include="Snappier" />Project file
paket add Snappier --version 1.3.1
#r "nuget: Snappier, 1.3.1"
#:package Snappier@1.3.1
#addin nuget:?package=Snappier&version=1.3.1Install as a Cake Addin
#tool nuget:?package=Snappier&version=1.3.1Install as a Cake Tool
Snappier is a pure C# port of Google's Snappy compression algorithm. It is designed with speed as the primary goal, rather than compression ratio, and is ideal for compressing network traffic. Please see the Snappy README file for more details on Snappy.
Complete documentation is available at https://brantburnett.github.io/Snappier/.
The Snappier project aims to meet the following needs of the .NET community.
Simply add a NuGet package reference to the latest version of Snappier.
<PackageReference Include="Snappier" Version="1.1.6" />
or
dotnet add package Snappier
using Snappier;
public class Program
{
private static byte[] Data = {0, 1, 2}; // Wherever you get the data from
public static void Main()
{
// This option uses `MemoryPool<byte>.Shared`. However, if you fail to
// dispose of the returned buffers correctly it can result in inefficient garbage collection.
// It is important to either call .Dispose() or use a using statement.
// Compression
using (IMemoryOwner<byte> compressed = Snappy.CompressToMemory(Data))
{
// Decompression
using (IMemoryOwner<byte> decompressed = Snappy.DecompressToMemory(compressed.Memory.Span))
{
// Do something with the data
}
}
}
}
Compressing or decompressing a stream follows the same paradigm as other compression streams in .NET. SnappyStream wraps an inner stream. If decompressing you read from the SnappyStream, if compressing you write to the SnappyStream
This approach reads or writes the Snappy framing format designed for streaming. The input/output is not the same as the block method above. It includes additional headers and CRC32C checks.
using System.IO;
using System.IO.Compression;
using Snappier;
public class Program
{
public static async Task Main()
{
using var fileStream = File.OpenRead("somefile.txt");
// First, compression
using var compressed = new MemoryStream();
using (var compressor = new SnappyStream(compressed, CompressionMode.Compress, leaveOpen: true))
{
await fileStream.CopyToAsync(compressor);
// Disposing the compressor also flushes the buffers to the inner stream
// We pass true to the constructor above so that it doesn't close/dispose the inner stream
// Alternatively, we could call compressor.Flush()
}
// Then, decompression
compressed.Position = 0; // Reset to beginning of the stream so we can read
using var decompressor = new SnappyStream(compressed, CompressionMode.Decompress);
var buffer = new byte[65536];
var bytesRead = decompressor.Read(buffer, 0, buffer.Length);
while (bytesRead > 0)
{
// Do something with the data
bytesRead = decompressor.Read(buffer, 0, buffer.Length)
}
}
}
There are other projects available for C#/.NET which implement Snappy compression.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 is compatible. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Snappier:
| Package | Downloads |
|---|---|
|
MongoDB.Driver
Official .NET driver for MongoDB. |
|
|
MongoDB.Driver.Core
Core Component of the Official MongoDB .NET Driver. |
|
|
Parquet.Net
Fully managed Apache Parquet implementation. |
|
|
CouchbaseNetClient
The Official Couchbase .NET SDK. |
|
|
IronCompress
Buffer compresison library supporting all the major compression algorithms (gzip, brotli, snappy, zstd etc.) |
Showing the top 20 popular GitHub repositories that depend on Snappier:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
elsa-workflows/elsa-core
The Workflow Engine for .NET
|
|
|
openiddict/openiddict-core
Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
|
|
|
ravendb/ravendb
ACID Document Database
|
|
|
mongodb/mongo-csharp-driver
The Official C# .NET Driver for MongoDB
|
|
|
Nethereum/Nethereum
Ethereum .Net cross platform integration library
|
|
|
NethermindEth/nethermind
A robust, high-performance execution client for Ethereum node operators.
|
|
|
qq362946/Fantasy
C # Game Framework, but not limited to games. Can be used for non game business development
|
|
|
jfrog/project-examples
Small projects in universal build ecosystems to configure CI and Artifactory
|
|
|
aloneguid/parquet-dotnet
Fully managed Apache Parquet implementation
|
|
|
imperugo/StackExchange.Redis.Extensions
StackExchange.Redis.Extensions is a library that extends StackExchange.Redis, making it easier to work with Redis in .NET applications
|
|
|
jeangatto/ASP.NET-Core-Clean-Architecture-CQRS-Event-Sourcing
ASP.NET Core, C#, CQRS Event Sourcing, REST API, DDD, SOLID Principles and Clean Architecture
|
|
|
mjebrahimi/EasyCompressor
⚡An Easy-to-Use and Optimized compression library for .NET that unified several compression algorithms including LZ4, Snappy, Zstd, LZMA, Brotli, GZip, ZLib, and Deflate. This library aids in Improving Performance by Reducing Memory Usage and Bandwidth Usage. Along with a greate Performance Benchmark between different compression algorithms.
|
|
|
alexandre-spieser/mongodb-generic-repository
An example of generic repository implementation using the MongoDB C# Sharp 2.0 driver (async)
|
|
|
couchbase/couchbase-net-client
The official Couchbase SDK for .NET Core and Full Frameworks
|
|
|
hcmlab/nova
NOVA is a tool for annotating and analyzing behaviours in social interactions. It supports Annotators using Machine Learning already during the coding process. Further it features both, discrete labels and continuous scores and a visuzalization of streams recorded with the SSI Framework.
|
|
|
saul/demofile-net
Blazing fast cross-platform demo parser library for Counter-Strike 2 and Valve's Deadlock, written in C#.
|
|
|
mobitouchOS/MaIN.NET
NuGet package designed to make LLMs, RAG, and Agents first-class citizens in .NET
|
|
|
face-it/Hangfire.Tags
Add tags to Hangfire backgroundjobs
|
|
|
nanami5270/GARbro-Mod
Fork of morkt/GARbro
|