IronCompress 1.6.3
IronCompress
C++ compression methods joined together in one native library, cross-compiled for multiple architectures and exposed as a .NET library. .NET has built-in support for Gzip and Brotli (which is what this library is using) but other compression methods are either available only as native libraries hard (impossible for some) to consume, or ill-ported C# alternatives. In fact, I myself wrote one of them. Using native, original implementations is the way to go if you want to keep performance, security, and features up to date.
The library supports the following formats:
- Google Snappy [source].
- Facebook's Zstandard (zstd) [source].
- Gzip [source].
- Google Brotli [source] (.net standard 2.0 build uses native version instead).
- LZO [source].
- LZ4 [source].
And following architectures:
Format | Managed | Windows | Linux | Mac OSX | ◀️ OS Arch 🔽 |
|
---|---|---|---|---|---|---|
Snappy | ✅ via Snappier |
⛔ | ⛔ | ⛔ | x32 | |
✅ | ✅ | ⛔ | x64 | |||
⛔ | ✅ | ✅ | ARM64 | |||
Zstd | ✅ via ZstdSharp |
⛔ | ⛔ | ⛔ | x32 | |
✅ | ✅ | ⛔ | x64 | |||
⛔ | ✅ | ✅ | ARM64 | |||
Gzip | ✅ part of .NET |
⛔ | ⛔ | ⛔ | x32 | |
⛔ | ⛔ | ⛔ | x64 | |||
⛔ | ⛔ | ⛔ | ARM64 | |||
Brotli | ✅ except on .NET Standard 2.0 |
⛔ | ⛔ | ⛔ | x32 | |
✅ | ✅ | ⛔ | x64 | |||
⛔ | ✅ | ✅ | ARM64 | |||
LZO | ⛔ | ⛔ | ⛔ | ⛔ | x32 | |
✅ | ✅ | ⛔ | x64 | |||
⛔ | ✅ | ✅ | ARM64 | |||
LZ4 | ⛔ | ⛔ | ⛔ | ⛔ | x32 | |
✅ | ✅ | ⛔ | x64 | |||
⛔ | ✅ | ✅ | ARM64 |
I periodically update to the latest binaries. All the binaries are compiled from C/C++ source with CMake
for major systems i.e. Linux, Windows and Mac OSX. They are then wrapped safely with a .NET interface.
Logic
Although managed versions are available, they will be only used as a fallback when native library is not available, because native libraries are faster and more up to date with latest advancements.
You can check which version was used by reading IronCompressResult.NativeUsed
flag.
Using
This library only compresses buffers. It may work with streams in the future, but I am currently only interested in buffers. Essentially, you pass ReadOnlySpan<byte>
as an input, and receive Span<T>
as an output in the most efficient way.
Here is an example of how to compress buffer with snappy codec:
using IronCompress; // root namespace
// Construct library entry point and optionally pass an implementation of ArrayPool.
// I will pass default shared pool here.
var iron = new Iron();
byte[] input = ...;
using(IronCompressResult compressed = iron.Compress(Codec.Snappy, input.AsSpan())) {
// ... use data
}
Compress
and Decompress
methods actually return a Result
class which wraps byte array of compression or decompression operation. You can access the underlying result by calling to .AsSpan()
method inside the result. On dispose, Result
makes sure the underlying memory is freed up - if pooling was used, it will be returned back to the pool.
To decompress:
using (IronCompressResult uncompressed = iron.Decompress(Codec.Snappy, compressed, input.Length)) {
// ... use data
}
As with compression, this returns Result
with decompressed data. It's worth nothing one important difference - decompression needs the length of output buffer specified as third parameter (input.Length
). Although some decompressors can guess uncompressed length more or less correct, the others won't know it beforehand. In reality this problem is solved by using a framing format that adds metadata about resulting length, however many compression formats do not define that and consider compressed packets to be implementation specific.
You will need more or less recent C++ compiler, CMake
and .NET SDK 8
to build the code.
Building
See workflow file for building instructions.
Hint: To develop managed only code locally you can download the latest artifact from Actions output and put it into native/ubin
so you have binaries for all platforms.
Showing the top 20 packages that depend on IronCompress.
Packages | Downloads |
---|---|
Elsa
Bundles the most commonly-used packages when building an Elsa workflows application.
|
4 |
Elsa.JavaScript
Provides a JavaScript expression provider.
|
4 |
Elsa.JavaScript
Provides a JavaScript expression provider.
|
6 |
Elsa.Workflows.Management
Provides workflow management functionality.
|
4 |
Elsa.Workflows.Management
Provides workflow management functionality.
|
5 |
Elsa.Workflows.Management
Provides workflow management functionality.
|
6 |
Elsa.Workflows.Management
Provides workflow management functionality.
|
7 |
Elsa.Workflows.Management
Provides workflow management functionality.
|
10 |
Elsa.Workflows.Runtime
Provides workflow runtime functionality.
|
5 |
Elsa.Workflows.Runtime
Provides workflow runtime functionality.
|
6 |
.NET 6.0
- Snappier (>= 1.1.6)
- ZstdSharp.Port (>= 0.8.1)
.NET 8.0
- Snappier (>= 1.1.6)
- ZstdSharp.Port (>= 0.8.1)
.NET Standard 2.0
- Snappier (>= 1.1.6)
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- ZstdSharp.Port (>= 0.8.1)
.NET Standard 2.1
- Snappier (>= 1.1.6)
- ZstdSharp.Port (>= 0.8.1)
Version | Downloads | Last updated |
---|---|---|
1.6.3 | 5 | 11/24/2024 |
1.6.2 | 5 | 12/02/2024 |
1.6.1 | 3 | 11/28/2024 |
1.6.1-pre.1 | 3 | 11/29/2024 |
1.6.0 | 3 | 11/29/2024 |
1.6.0-pre.1 | 3 | 12/02/2024 |
1.5.2 | 4 | 12/02/2024 |
1.5.2-pre.1 | 3 | 11/28/2024 |
1.5.1 | 5 | 12/01/2024 |
1.5.0 | 3 | 12/04/2024 |
1.4.0 | 1 | 12/27/2024 |
1.3.0 | 4 | 12/02/2024 |
1.2.8 | 0 | 01/26/2023 |
1.2.7 | 4 | 12/05/2024 |
1.2.6 | 5 | 12/02/2024 |
1.2.5 | 4 | 12/02/2024 |
1.2.4 | 2 | 12/09/2024 |
1.2.3 | 2 | 12/08/2024 |
1.2.2 | 5 | 11/29/2024 |
1.2.0 | 4 | 11/29/2024 |
1.1.5 | 5 | 12/01/2024 |
1.1.4 | 4 | 12/02/2024 |
1.1.3 | 3 | 12/13/2024 |
1.1.2 | 3 | 11/27/2024 |
1.1.1 | 4 | 12/02/2024 |
1.1.0 | 5 | 12/01/2024 |
1.0.0 | 2 | 12/08/2024 |
1.0.0-preview-03 | 3 | 12/01/2024 |
1.0.0-preview-02 | 2 | 12/08/2024 |
1.0.0-preview-01 | 2 | 12/09/2024 |