{"id":15036298,"url":"https://github.com/brantburnett/snappier","last_synced_at":"2025-04-11T23:16:14.644Z","repository":{"id":46036340,"uuid":"302450748","full_name":"brantburnett/Snappier","owner":"brantburnett","description":"High performance C# implementation of the Snappy compression algorithm","archived":false,"fork":false,"pushed_at":"2025-01-30T19:08:31.000Z","size":1853,"stargazers_count":78,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T23:16:08.179Z","etag":null,"topics":["compression","csharp","csharp-library","hacktoberfest","netcore","snappy"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brantburnett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"COPYING.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-08T20:10:17.000Z","updated_at":"2025-04-01T03:33:52.000Z","dependencies_parsed_at":"2023-11-09T02:24:10.763Z","dependency_job_id":"0f7553e8-8f47-4d8c-9398-aaf6c160b0cf","html_url":"https://github.com/brantburnett/Snappier","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2FSnappier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2FSnappier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2FSnappier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brantburnett%2FSnappier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brantburnett","download_url":"https://codeload.github.com/brantburnett/Snappier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492884,"owners_count":21113163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compression","csharp","csharp-library","hacktoberfest","netcore","snappy"],"created_at":"2024-09-24T20:30:44.681Z","updated_at":"2025-04-11T23:16:14.622Z","avatar_url":"https://github.com/brantburnett.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snappier\n\n## Introduction\n\nSnappier is a pure C# port of Google's [Snappy](https://github.com/google/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](https://github.com/google/snappy/blob/master/README.md) for more details on Snappy.\n\nComplete documentation is available at https://brantburnett.github.io/Snappier/.\n\n## Project Goals\n\nThe Snappier project aims to meet the following needs of the .NET community.\n\n- Cross-platform C# implementation for Linux and Windows, without P/Invoke or special OS installation requirements\n- Compatible with .NET 4.6.1 and later and .NET 6 and later\n- Use .NET paradigms, including asynchronous stream support\n- Full compatibility with both block and stream formats\n- Near C++ level performance\n  - Note: This is only possible on .NET 6 and later with the aid of [Span\u0026lt;T\u0026gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1?view=net-9.0) and [System.Runtime.Intrinsics](https://devblogs.microsoft.com/dotnet/dotnet-8-hardware-intrinsics/)\n  - .NET 4.6.1 is the slowest\n- Keep allocations and garbage collection to a minimum using buffer pools\n\n## Installing\n\nSimply add a NuGet package reference to the latest version of Snappier.\n\n```xml\n\u003cPackageReference Include=\"Snappier\" Version=\"1.1.6\" /\u003e\n```\n\nor\n\n```sh\ndotnet add package Snappier\n```\n\n## Block compression/decompression using a memory pool buffer\n\n```cs\nusing Snappier;\n\npublic class Program\n{\n    private static byte[] Data = {0, 1, 2}; // Wherever you get the data from\n\n    public static void Main()\n    {\n        // This option uses `MemoryPool\u003cbyte\u003e.Shared`. However, if you fail to\n        // dispose of the returned buffers correctly it can result in inefficient garbage collection.\n        // It is important to either call .Dispose() or use a using statement.\n\n        // Compression\n        using (IMemoryOwner\u003cbyte\u003e compressed = Snappy.CompressToMemory(Data))\n        {\n            // Decompression\n            using (IMemoryOwner\u003cbyte\u003e decompressed = Snappy.DecompressToMemory(compressed.Memory.Span))\n            {\n                // Do something with the data\n            }\n        }\n    }\n}\n```\n\n## Stream compression/decompression\n\nCompressing 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`\n\nThis approach reads or writes the [Snappy framing format](https://github.com/google/snappy/blob/master/framing_format.txt) designed for streaming. The input/output is not the same as the block method above. It includes additional headers and CRC32C checks.\n\n```cs\nusing System.IO;\nusing System.IO.Compression;\nusing Snappier;\n\npublic class Program\n{\n    public static async Task Main()\n    {\n        using var fileStream = File.OpenRead(\"somefile.txt\");\n\n        // First, compression\n        using var compressed = new MemoryStream();\n\n        using (var compressor = new SnappyStream(compressed, CompressionMode.Compress, leaveOpen: true))\n        {\n            await fileStream.CopyToAsync(compressor);\n\n            // Disposing the compressor also flushes the buffers to the inner stream\n            // We pass true to the constructor above so that it doesn't close/dispose the inner stream\n            // Alternatively, we could call compressor.Flush()\n        }\n\n        // Then, decompression\n\n        compressed.Position = 0; // Reset to beginning of the stream so we can read\n        using var decompressor = new SnappyStream(compressed, CompressionMode.Decompress);\n\n        var buffer = new byte[65536];\n        var bytesRead = decompressor.Read(buffer, 0, buffer.Length);\n        while (bytesRead \u003e 0)\n        {\n            // Do something with the data\n\n            bytesRead = decompressor.Read(buffer, 0, buffer.Length)\n        }\n    }\n}\n```\n\n## Other Projects\n\nThere are other projects available for C#/.NET which implement Snappy compression.\n\n- [Snappy.NET](https://snappy.machinezoo.com/) - Uses P/Invoke to C++ for great performance. However, it only works on Windows, is a bit heap allocation heavy in some cases, and is a deprecated project. This project may still be the best choice if your project is on the legacy .NET Framework on Windows, where Snappier is much less performant.\n- [IronSnappy](https://www.nuget.org/packages/IronSnappy) - Another pure C# port, based on the Golang implementation instead of the C++ implementation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrantburnett%2Fsnappier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrantburnett%2Fsnappier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrantburnett%2Fsnappier/lists"}