Repolode
Cysharp

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. 1

    Install the NativeCompressions package from NuGet

    dotnet add package NativeCompressions
  2. 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

#compression#lz4#zstandard#dotnet#csharp#unity#native-bindings#streaming

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