⚡ 一个易于使用且经过优化的 .NET 压缩库,整合了多种压缩算法,包括 LZ4、Snappy、Zstd、LZMA、Brotli、GZip、ZLib 等。
⚡ 一个易于使用且经过优化的 .NET 压缩库,整合了多种压缩算法,包括 LZ4、Snappy、Zstd、LZMA、Brotli、GZip、ZLib 等。
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)
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.
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.
| Package | Description |
|---|---|
| EasyCompressor | Including Algorithms : |
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.
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)…………using EasyCompressor;
public class YourClass
{
private readonly ICompressor _lz4Compressor;
private readonly ICompressor _snappierCompressor;
private readonly ICompressor _zstdsharpCompressor;
public YourClass(ICompressorProvider compressorProvider)
{
_lz4Compressor = compressorProvider.GetCompressor("lz4");
_snappierCompressor = compressorProvider.GetCompressor("snappier");
_zstdsharpCompressor = compressor.GetCompressor("zstdsharp");
}
}To view the Full benchmark, visit this HTML Page.
| Operation | Binary | Stream | StreamAsync |
|---|---|---|---|
| Compress | SnappierCompressor | ||
| LZ4Compressor | |||
| ZstdSharpCompressor | SnappierCompressor | ||
| LZ4Compressor | |||
| BrotliCompressor | LZ4Compressor | ||
| BrotliCompressor |
All the benchmarks are visualized using BenchmarkDotNetVisualizer.
LZ4Compressor.Shared.Compress(bytes);暂无开放 Issues,或尚未同步最近议题。