EasyCompressor
A compression library that implements many compression algorithms such as LZ4, Zstd, LZMA, Snappy, Brotli, GZip, and Deflate. It helps you to improve performance by reducing Memory Usage and Network Traffic for caching.
Nuget Packages
Package Name | Version | Description |
---|---|---|
EasyCompressor | Contains GZip, Deflate and (Brotli available only in .NETCore2.1, .NETStandard2.1 and above) | |
EasyCompressor.BrotliNET | Contains Brotli using Brotli.NET (for erlier than .NETCore2.1, .NETStandard2.1) | |
EasyCompressor.LZ4 | Contains LZ4 using K4os.Compression.LZ4 | |
EasyCompressor.LZMA | Contains LZMA using LZMA-SDK | |
EasyCompressor.Snappy | Contains Snappy using Snappy.Standard | |
EasyCompressor.Zstd | Contains Zstd (ZStandard) using ZstdNet | |
EasyCaching.Extensions.EasyCompressor | This integrates EasyCaching with EasyCompressor. (How to use) |
Note :
LZ4
, GZip
, Deflate
, Brotli
, and LZMA
are cross-platform because these are complete implementations with C#. (also BrotliNet
too because this is a wrapper of brotli native library for win/linux/osx)
Zstd
and Snappy
are not cross-platform, because they are just a wrapper of the native library for windows.
Features
- Supports and implements many compression algorithms.
- Supports async/await and CancellationToken.
- Supports woking with multiple compressors with specified names
- Supports Stream as most as possible (depending on the underlying library)
- Compress/Decompress between byte[], Stream, StreamReader and StreamWriter.
Get Started
1. Install Package
PM> Install-Package EasyCompressor.LZ4
2. Add Services
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddLZ4Compressor();
//or services.AddGZipCompressor(); package : EasyCompressor
//or services.AddDeflateCompressor(); package : EasyCompressor
//or services.AddBrotliCompressor(); package : EasyCompressor
//or services.AddBrotliNetCompressor(); package : EasyCompressor.BrotliNET
//or services.AddZstdCompressor(); package : EasyCompressor.Zstd
//or services.AddLZMACompressor(); package : EasyCompressor.LZMA
//or services.AddSnappyCompressor(); package : EasyCompressor.Snappy
}
3. Use it
using EasyCompressor;
// Inject (ICompressor compressor)
// Compress
var compressedBytes = compressor.Compress(inputBytes);
// Decompress
var uncompressedBytes = compressor.Decompress(compressedBytes);
Benchmark
Tips and Results
Original data size is:
- 89,535 bytes (about ≈ 90 KB) (binary serialized output of a json file by messagepack).
Compressed data size (for example):
- 776 bytes for Zstd (115x compression ratio) that results in 99.13% memory and bandwidth saving.
- 1,234 bytes for LZ4 (72x compression ratio) that results in 98.62% memory and bandwidth saving.
Maximum Compression:
- Brotli
- Zstd
- LZMA
- LZ4
Fastest Speed:
- Zstd
- Snappy
- LZ4
Most Efficient:
- Zstd (windows only package)
- LZ4 (cross-platform package)
Moderated:
- GZip
- Deflate
Compression Ratio : higher is better
Contributing
Create an issue if you find a BUG or have a Suggestion or Question. If you want to develop this project :
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
⭐️
Give a Star! If you find this repository useful, please give it a star. Thanks!
License
EasyCompressor is Copyright © 2020 Mohammd Javad Ebrahimi under the MIT License.