Skip to content

A simple zlib wrapper with NativeAOT support, browser-wasm, and transparent C lib build.

License

Notifications You must be signed in to change notification settings

BigBang1112/NativeSharpZlib

Repository files navigation

NativeSharpZlib

Nuget GitHub release (latest by date including pre-releases) Code Coverage

A simple zlib wrapper with NativeAOT support and transparent C lib build.

Another zlib wrapper for C#, as there wasn't one where you'd be able to set concrete de/compress block sizes, which is crucial for decompressing certain encrypted content.

Supported runtimes:

  • win-x64
  • win-x86
  • linux-x64
  • linux-arm
  • linux-arm64
  • browser-wasm

Usage

var data = Encoding.UTF8.GetBytes("Hello, World!");

using var ms = new MemoryStream();
using (var compressStream = new NativeZlibStream(ms, CompressionMode.Compress, leaveOpen: true))
{
    compressStream.Write(data, 0, data.Length);
}

ms.Position = 0;

using var decompressStream = new NativeZlibStream(ms, CompressionMode.Decompress);
var buffer = new byte[256];
var read = decompressStream.Read(buffer, 0, buffer.Length);

Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, read));

You can also specify block sizes and compression level in NativeZlibOptions.

using var zlibStream = new NativeZlibStream(stream, CompressionMode.Compress, new NativeZlibOptions()
{
    CompressedBlockSize = 512,
    UncompressedBlockSize = 2048,
    CompressionLevel = 9,
});

About

A simple zlib wrapper with NativeAOT support, browser-wasm, and transparent C lib build.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages