Extremely fast MessagePack serializer for C# covering .NET, .NET Core, Unity and Xamarin, with built-in LZ4 compression.
Cysharp/NativeCompressions
C# native bindings and high-level streaming APIs for LZ4, Zstandard and experimental OpenZL, for .NET and Unity.
- Stars
- 320
- Forks
- 11
- Open issues
- 0
- Last commit
- 2 days ago
What is it?
NativeCompressions wraps the native LZ4 and Zstandard libraries for .NET and Unity, exposing simple byte-array APIs as well as streaming encoders, decoders, Stream wrappers and PipeReader/PipeWriter-based async methods. The project uses the official native implementations rather than pure C# ports so it keeps up with upstream performance and security updates.
The LZ4 API uses the frame format and supports options such as compression level, block size, checksums and external dictionaries. Zstandard offers a similar API with dictionary training. Prebuilt native libraries cover Windows, Linux, macOS, Android, iOS and Mac Catalyst, and a WebAssembly path is documented for Blazor. OpenZL bindings are included as experimental, without a NuGet package or high-level API yet.
Packages are split so you can install only the algorithm or platform runtimes you need, and a Unity setup guide covers NuGetForUnity configuration.
Key features
- 01Native LZ4 and Zstandard bindings with byte-array and span-based APIs.
- 02Streaming encoders and decoders that return OperationStatus, similar to BrotliEncoder.
- 03Async compression over Stream, PipeReader and PipeWriter.
- 04Dictionary support, including Zstandard dictionary training for LZ4.
- 05Prebuilt native libraries for major desktop, mobile and Apple platforms.
- 06Experimental OpenZL bindings exposed through the raw C API.
Use cases
- Compressing network payloads or cached data in a .NET service.
- Adding fast LZ4 decompression to Unity games that load compressed assets.
- Choosing between LZ4 and Zstandard for different speed and ratio trade-offs.
- Compressing data on Blazor WebAssembly apps with the documented native build.
Quick start
- 1
Install the NativeCompressions package from NuGet
dotnet add package NativeCompressions - 2
Call LZ4.Compress and LZ4.Decompress, or Zstandard.Compress and Zstandard.Decompress, in your code
Things to know
- OpenZL is experimental, has native bindings only, and has no NuGet package.
- The macOS native libraries require macOS 15.0 or later.
- iOS and Mac Catalyst apps need .NET 10 or later.
- 32-bit processes are not supported.
In collections
Topics
FAQ
- What is NativeCompressions?
- C# native bindings and high-level streaming APIs for LZ4, Zstandard and experimental OpenZL, for .NET and Unity. NativeCompressions wraps the native LZ4 and Zstandard libraries for .NET and Unity, exposing simple byte-array APIs as well as streaming encoders, decoders, Stream wrappers and PipeReader/PipeWriter-based async methods. The project uses the official native implementations rather than pure C# ports so it keeps up with upstream performance and security updates.
- Is NativeCompressions free to use? What license does it have?
- NativeCompressions is open source under the MIT license. Check the license terms before using it in commercial products.
- Is NativeCompressions still maintained?
- Actively maintained. The last commit to NativeCompressions was on Nov 5, 2026.
- What can I use NativeCompressions for?
- Compressing network payloads or cached data in a .NET service. Adding fast LZ4 decompression to Unity games that load compressed assets. Choosing between LZ4 and Zstandard for different speed and ratio trade-offs. Compressing data on Blazor WebAssembly apps with the documented native build.
- How do I install NativeCompressions?
- Install the NativeCompressions package from NuGet: dotnet add package NativeCompressions Call LZ4.Compress and LZ4.Decompress, or Zstandard.Compress and Zstandard.Decompress, in your code
- Where can I get NativeCompressions?
- The source code and installation instructions are on GitHub: https://github.com/Cysharp/NativeCompressions
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Extremely fast lossless compression algorithm in C, with a very fast decoder and a tunable speed-versus-ratio trade-off.
Unofficial continuation of dnSpy, a debugger and editor for .NET and Unity assemblies that works without source code.
A high-performance, low-allocation YAML 1.2 library for C# focused on .NET and Unity, with source-generated serialization.
A plugin and modding framework that lets developers and players load custom code into Unity, XNA, FNA and MonoGame games.
A scripting solution that lets Unity and Unreal Engine games be written in TypeScript/JavaScript, with Lua and Python backends for Unity.