SkillAgentSearch skills...

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.

Install / Use

/learn @mjebrahimi/EasyCompressor

README

NuGet NuGet License: MIT Build Status

EasyCompressor

<img src="/src/EasyCompressor.png" width="100" height="100" align="left"/>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.

Along with a great Performance Benchmark between different compression algorithms.

This library aids in Improving Performance by Reducing Memory Usage and Bandwidth Usage. (see How)

Usage

  • Compress your BLOB data for Archiving and Saving the Storage (on average from 30% to 90%)
  • Compress your Caching objects for Saving the Memory Usage (it also has a nice integration with EasyCaching)
  • Reduce the Bandwidth Usage of your network by reducing the volume of data sent or received. (see How)
  • Improve the Performance of your I/O Operations like Service-to-Service Communication. (see How)

Features

  • Offers a range of compression algorithms, including LZ4, Snappy, Zstd, LZMA, Brotli, GZip, ZLib, and Deflate.
  • Support for async/await operations with support of CancellationToken.
  • Stream operations are fully supported.
  • Optimized and implemented with a focus on performance.

Note

The default comparison levels are carefully configured based on extensive benchmarking to ensure the highest level of efficiency and speed at a reasonable compression ratio.

Improving Data Transfer Speed by Sending/Receiving Less

Compression/Decompression has overhead but it reduces the size of your data, which can potentially result in faster transfer times, even when accounting for the additional time required for compression and decompression.

When a file is compressed, it becomes smaller in size, which means it requires less bandwidth to transfer. If the compression ratio is significant, the reduced file size can compensate for the extra time needed for compression and decompression.

For example, let's say you have an uncompressed file that takes 10 seconds to transfer. If you compress this file using a fast compressor like LZ4, Snappy, or Zstd, the compression time might be around 1 second. However, the compressed file size is significantly smaller, let's say it's only 20% of the original size. Now, when you transfer the compressed file, it will only take 2 seconds (20% of the original transfer time). In this scenario, the total time (compression time + transfer time) would be 3 seconds (1 second for compression + 2 seconds for transfer), which is less than the original 10 seconds it would have taken to transfer the uncompressed file.

It's important to note that the actual time savings will depend on various factors, such as the compression ratio achieved, the speed of the compression and decompression algorithms, the network bandwidth, and other system-specific considerations. However, with fast compressors like LZ4, Snappy, or Zstd and significant compression ratios, it is possible to achieve overall time savings when transferring compressed files compared to transferring uncompressed files.

Nuget Packages

| Package | Description | ------------ | ---------------------- | EasyCompressor | Including Algorithms :<br/>- Brotli (Highest compression ratio - the Smallest size) (Only available in .NETCoreApp2.1, .NETStandard2.1 and above)<br/>- GZip<br/>- Deflate<br/>- ZLib (Only available in .NET6.0 and above) | EasyCompressor.LZ4⭐️ | Algorithm: LZ4<br/>Extremely Fast (Recommended - see Benchmarks) | EasyCompressor.Snappier⭐️ | Algorithm: Snappy<br/>Extremely Fast (Recommended - see Benchmarks) | EasyCompressor.ZstdSharp⭐️ | Algorithm: Zstd (Zstandard)<br/>Extremely Fast (Recommended - see Benchmarks) | EasyCompressor.LZMA | Algorithm: LZMA<br/>High compression ratio (small size) but very Slow (Not recommended - see Benchmarks) | EasyCompressor.Zstd (deprecated) | Instead, use EasyCompressor.ZstdSharp. | EasyCompressor.Snappy (deprecated) | Instead, use EasyCompressor.Snappier | EasyCompressor.BrotliNET (deprecated) | Instead, use BrotliCompressor in EasyCompressor itself (base package)<br/>(Use only if your project targets .NETFramework462 and above or .NETCoreApp2.0) | EasyCaching.Extensions.EasyCompressor⭐️ | A winning combination by integrating with EasyCaching to compress your cache data. (Recommended)<br/>See How to use

Note :

All of these packages are cross-platform except EasyCompressor.Zstd and EasyCompressor.Snappy which are not cross-platform because their underlying library are just a wrapper around the native dlls only for windows.

Get Started

1. Install Package

PM> Install-Package EasyCompressor.LZ4

PM> # Install-Package EasyCompressor (for Brotli, GZip, Deflate, ZLib)
PM> # Install-Package EasyCompressor.Snappier
PM> # Install-Package EasyCompressor.ZstdSharp
PM> # Install-Package EasyCompressor.LZMA
PM> # Install-Package EasyCompressor.Zstd (deprecated)
PM> # Install-Package EasyCompressor.Snappy (deprecated)
PM> # Install-Package EasyCompressor.BrotliNET (deprecated)

2. Using New Instance or the Shared Instance

public class YourClass
{
    private readonly ICompressor _compressor;

    public YourClass()
    {
        //--------------------------------------- New Instance ---------------------------------------
        _compressor = new LZ4Compressor();            //package : EasyCompressor.LZ4

        //_compressor = new ZstdSharpCompressor();    //package : EasyCompressor.Snappier
        //_compressor = new BrotliCompressor();       //package : EasyCompressor
        //_compressor = new GZipCompressor();         //package : EasyCompressor
        //_compressor = new DeflateCompressor();      //package : EasyCompressor
        //_compressor = new ZLibCompressor();         //package : EasyCompressor
        //_compressor = new LZMACompressor();         //package : EasyCompressor.LZMA
        //_compressor = new ZstdCompressor();         //package : EasyCompressor.Zstd (deprecated)
        //_compressor = new SnappyCompressor();       //package : EasyCompressor.Snappy (deprecated)
        //_compressor = new BrotliNETCompressor();    //package : EasyCompressor.BrotliNET (deprecated)


        //--------------------------------------- Shared Instance ---------------------------------------
        _compressor = LZ4Compressor.Shared;            //package : EasyCompressor.LZ4

        //_compressor = ZstdSharpCompressor.Shared;    //package : EasyCompressor.Snappier
        //_compressor = BrotliCompressor.Shared;       //package : EasyCompressor
        //_compressor = GZipCompressor.Shared;         //package : EasyCompressor
        //_compressor = DeflateCompressor.Shared;      //package : EasyCompressor
        //_compressor = ZLibCompressor.Shared;         //package : EasyCompressor
        //_compressor = LZMACompressor.Shared;         //package : EasyCompressor.LZMA
        //_compressor = ZstdCompressor.Shared;         //package : EasyCompressor.Zstd (deprecated)
        //_compressor = SnappyCompressor.Shared;       //package : EasyCompressor.Snappy (deprecated)
        //_compressor = BrotliNETCompressor.Shared;    //package : EasyCompressor.BrotliNET (deprecated)
    }

    static static void ProcessData(byte[] bytes)
    {
        // Compress your original byte[] and return compressed byte[]
        var compressedBytes = _compressor

Related Skills

View on GitHub
GitHub Stars381
CategoryDevelopment
Updated9d ago
Forks21

Languages

C#

Security Score

100/100

Audited on Mar 18, 2026

No findings