LZ4.AI.Sharp 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package LZ4.AI.Sharp --version 1.0.2
                    
NuGet\Install-Package LZ4.AI.Sharp -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LZ4.AI.Sharp" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LZ4.AI.Sharp" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="LZ4.AI.Sharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LZ4.AI.Sharp --version 1.0.2
                    
#r "nuget: LZ4.AI.Sharp, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LZ4.AI.Sharp@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LZ4.AI.Sharp&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=LZ4.AI.Sharp&version=1.0.2
                    
Install as a Cake Tool

LZ4.AI.Sharp

⚠️ AI-Generated Code — This entire library was migrated from C to C# and performance-tuned using GitHub Copilot.

NuGet License

A high-performance C#/.NET implementation of the LZ4 compression algorithm, featuring both fast and high-compression modes. This library was created as an AI-assisted port of the LZ4 reference implementation to demonstrate modern AI-powered code migration and optimization.

Features

  • Fast Compression (LZ4Codec) — Optimized for speed with competitive compression ratios
  • High Compression (LZ4HC) — Better compression ratios at slower speeds
  • Frame Format (LZ4Frame) — Stream-oriented API with checksums and metadata
  • XXHash — Fast non-cryptographic hash function
  • Pure Managed C# — No external native library dependencies, runs on any .NET platform (uses unsafe code for performance)
  • Zero Allocations — Work directly with byte arrays and spans

Installation

dotnet add package LZ4.AI.Sharp

Quick Start

Fast Compression

using LZ4Sharp;

byte[] input = GetYourData();
byte[] compressed = new byte[LZ4Codec.CompressBound(input.Length)];
// accel: 1 (higher compression) to 65537 (faster), default is 1
int compressedSize = LZ4Codec.CompressFast(input, compressed, input.Length, compressed.Length, acceleration: 1);

byte[] decompressed = new byte[input.Length];
LZ4Codec.DecompressSafe(compressed, decompressed, compressedSize, decompressed.Length);

High Compression

using LZ4Sharp;

byte[] compressed = new byte[LZ4HC.CompressBound(input.Length)];
int compressedSize = LZ4HC.CompressHC(input, compressed, input.Length, compressed.Length);

Performance

See BENCHMARKS.md for detailed performance results on JSON and Silesia corpus datasets.

Highlights (Intel N100, .NET 10):

  • JSON dataset: ratios 0.29–0.77 vs K4os (1.3x–3.4x faster)
  • Silesia corpus (accel=1): ratios 0.09–1.00 vs K4os (up to 11.1x faster)
  • Silesia: faster in 11/12 files at accel=1
  • Compression ratios: Match the reference implementation

Testing

The test suite includes:

  • Unit Tests — Comprehensive algorithm correctness tests
  • Compatibility Tests — Cross-validation with K4os.Compression.LZ4 to ensure interoperability
  • Round-trip Tests — Compression/decompression verification

All tests verify that LZ4Sharp produces output compatible with other LZ4 implementations.

Development

# Build
dotnet build src/LZ4Sharp.sln -c Release

# Test
dotnet test src/LZ4Sharp.sln -c Release

# Run benchmarks
dotnet run --project src/LZ4Sharp.Benchmarks -c Release

# Package
dotnet pack src/LZ4Sharp/LZ4Sharp.csproj -c Release

AI Provenance

This library is 100% AI-generated code:

  1. Migration — Ported from C reference implementation using GitHub Copilot
  2. Optimization — Performance-tuned through iterative AI-assisted refinement
  3. Testing — Test cases and benchmarks created with AI assistance

The project demonstrates AI capabilities in code translation, optimization, and maintaining algorithmic correctness while adapting to different language paradigms.

Attribution

License

MIT License — See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 139 2/13/2026
1.0.4 124 2/10/2026
1.0.3 126 2/8/2026
1.0.2 127 2/4/2026
1.0.0 142 1/13/2026