Universal.Common.IO.Compression
1.4.0
dotnet add package Universal.Common.IO.Compression --version 1.4.0
NuGet\Install-Package Universal.Common.IO.Compression -Version 1.4.0
<PackageReference Include="Universal.Common.IO.Compression" Version="1.4.0" />
<PackageVersion Include="Universal.Common.IO.Compression" Version="1.4.0" />
<PackageReference Include="Universal.Common.IO.Compression" />
paket add Universal.Common.IO.Compression --version 1.4.0
#r "nuget: Universal.Common.IO.Compression, 1.4.0"
#:package Universal.Common.IO.Compression@1.4.0
#addin nuget:?package=Universal.Common.IO.Compression&version=1.4.0
#tool nuget:?package=Universal.Common.IO.Compression&version=1.4.0
Universal.Common.IO.Compression
Compression codecs with no third-party package dependencies: Deflate, Gzip, Zlib, Brotli, Snappy, raw and Hadoop-framed LZ4, raw LZO1X, LZMA (classic and Unity-header variants), and Zstandard. Zstandard checksum validation uses Microsoft's System.IO.Hashing package.
Self-describing formats implement ICompressionAlgorithm. Deflate, Gzip, and Zlib also implement IStreamingCompressionAlgorithm. Raw LZ4 blocks implement ISizedCompressionAlgorithm because their uncompressed size is supplied separately.
Snappy, Brotli, Zstandard, LZMA, and Unity LZMA additionally accept an exact expected decoded size through ISizedCompressionAlgorithm. Raw LZO1X and Hadoop LZ4 require the size. Encoders use match compression for LZO1X and LZ4, adaptive Huffman coding for Brotli, and Huffman/FSE entropy coding for Zstandard. GZIP uses a managed, buffered DEFLATE decoder and validates every member's optional header checksum, CRC32, and decoded length on .NET Framework and modern .NET.
Quickstart
// LZ4 (ISizedCompressionAlgorithm - raw block format needs the original size to decompress)
Lz4CompressionAlgorithm lz4 = new Lz4CompressionAlgorithm();
byte[] lz4Compressed = lz4.Compress(data);
byte[] lz4Restored = lz4.Decompress(lz4Compressed, data.Length);
// LZMA, Zstandard, Deflate, Gzip, Zlib
LzmaCompressionAlgorithm lzma = new LzmaCompressionAlgorithm();
byte[] lzmaCompressed = lzma.Compress(data);
byte[] lzmaRestored = lzma.Decompress(lzmaCompressed);
ZstdCompressionAlgorithm zstd = new ZstdCompressionAlgorithm();
byte[] restored2 = zstd.Decompress(zstdCompressedBytes);
IStreamingCompressionAlgorithm zlib = new ZlibCompressionAlgorithm();
using Stream decompressor = zlib.CreateDecompressionStream(compressedInput);
decompressor.CopyTo(output);
// For zlib, compressedInput is now positioned immediately after this member.
// Limit decompression to one member embedded in a larger stream.
using Stream member = zlib.CreateDecompressionStream(container, compressedLength, leaveOpen: true);
await member.CopyToAsync(output);
// End-to-end asynchronous helpers are available for every streaming codec.
await zlib.CompressAsync(input, compressedOutput, cancellationToken);
await zlib.DecompressAsync(compressedInput, output, cancellationToken);
// Supply a known RFC 1950 preset dictionary when a zlib member requires it.
ZlibCompressionAlgorithm dictionaryZlib = new ZlibCompressionAlgorithm();
using Stream dictionaryMember = dictionaryZlib.CreateDecompressionStream(compressedInput, presetDictionary, leaveOpen: true);
await dictionaryMember.CopyToAsync(output);
Status
- Brotli: managed RFC 7932 decoder, including context modeling, static dictionary transforms, and all standard window sizes. The encoder writes LZ matches and adaptive Huffman-coded compressed metablocks, with uncompressed fallback when smaller. Tests cross-check native BCL Brotli across compression qualities, windows, and input patterns. Canonical dictionary and transform data carry the MIT license in
licenses/Brotli-MIT.txt; provenance and a data generation script are underBrotli. - LZ4, LZMA (+ Unity's own header variant): full encode and decode, verified byte-for-byte in both directions against independent real-world implementations (
lz4js, Python'slzmamodule). - Zstandard: frame/block parsing, FSE with predefined or custom tables, Huffman-coded literals, and sequence execution. The encoder writes LZ sequences with adaptive FSE tables and Huffman-coded literals, using Raw/RLE alternatives when smaller. Interoperability checks include native Zstandard and independent Apache Arrow C++ Parquet files.
- LZO1X: raw blocks with literal runs, short and long matches, and overlap handling; checked against native LZO vectors and an independent decoder.
- Deflate, Gzip, Zlib: synchronous and asynchronous streaming encode and decode. Async helpers stage output per input chunk so codec headers and finalization bytes reach the destination through asynchronous writes on .NET Standard 2.0. Zlib validates its header, advertised window, preset dictionary identifier, and Adler-32 checksum. Seekable inputs use buffered reads; non-seekable inputs use exact demand reads to preserve following members or container data, with bulk reads for stored blocks. Preset dictionaries are accepted for decoding through the explicit overload; encoding uses ordinary dictionary-free zlib streams.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.IO.Hashing (>= 11.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Universal.Common.IO.Compression:
| Package | Downloads |
|---|---|
|
Universal.Common.Formats.Fig
Reads and writes Figma .fig file containers and their Kiwi-encoded document data. |
|
|
Universal.Meta.WhatsApp.Client
WebSocket client for the WhatsApp multi-device protocol. |
|
|
Universal.Git
A Git-compatible repository implementation built on Universal.VersionControl. |
|
|
Universal.Apache.Parquet
Managed Apache Parquet file reading and writing. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Added adaptive Huffman Brotli encoding, Huffman/FSE Zstandard encoding, and match-based LZO1X encoding. Added a buffered managed GZIP decoder, zlib preset-dictionary decoding, and asynchronous streaming helpers that preserve asynchronous destination I/O through codec finalization. Hardened compressed-data validation and exact decoded-size checks. Brotli includes MIT-licensed normative dictionary and transform data.