OneCompress, OneArchive’s codec package, compresses raw Deflate64 bytes—not ZIP files.
dotnet add package RecursiveAI.OneCompressRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneCompress.Deflate64; byte[] input = "Hello Deflate64!"u8.ToArray(); byte[] packed = Deflate64.Compress(input); byte[] restored = Deflate64.Decompress(packed, new() { MaxOutputSize = 1024 }); Console.WriteLine( System.Text.Encoding.UTF8.GetString(restored));
Hello Deflate64!Unzip the example, then dotnet run.
The full program
The program generates Hello Deflate64! as UTF-8 bytes, checks the round trip and saves the compressed bytes to message.deflate64.
using RecursiveAI.OneCompress.Deflate64; byte[] input = "Hello Deflate64!"u8.ToArray(); byte[] packed = Deflate64.Compress(input); byte[] restored = Deflate64.Decompress(packed, new() { MaxOutputSize = 1024 }); Console.WriteLine( System.Text.Encoding.UTF8.GetString(restored)); Console.WriteLine($"Round-trip equal: {input.SequenceEqual(restored)}"); File.WriteAllBytes("message.deflate64", packed); Console.WriteLine("Wrote message.deflate64");
dotnet run prints:
Hello Deflate64! Round-trip equal: True Wrote message.deflate64
Malformed or truncated input throws CompressionFormatException; output above MaxOutputSize throws CompressionLimitException.
Variations
Choose level 9 and reject decompression that would exceed four bytes.
using RecursiveAI.OneCompress; using RecursiveAI.OneCompress.Deflate64; byte[] packed = Deflate64.Compress( "Hello Deflate64!"u8, new() { Level = 9 }); try { Deflate64.Decompress(packed, new() { MaxOutputSize = 4 }); } catch (CompressionLimitException) { Console.WriteLine("Output exceeds 4 bytes"); }
Output exceeds 4 bytesRelated recipes
- Create an ar archive in C#
- Create a cpio archive in C#
- List RAR 5 files and extract a stored entry in C#
The short answer
Call Deflate64.Compress and Deflate64.Decompress from RecursiveAI.OneCompress. Set MaxOutputSize when decoding so that the compressed input cannot request unlimited output.
These methods accept and return byte arrays. There are no filenames, archive entries or text encodings stored by the raw codec. UTF-8 belongs to this example’s application data, not to Deflate64 itself. Arbitrary binary data can be passed through the same methods without a text conversion.
How do I compress and decompress Deflate64 in C#?
Install RecursiveAI.OneCompress rather than adding an archive container around the data. The namespace is RecursiveAI.OneCompress.Deflate64; Deflate64 is the one-call API. Its compression options accept levels 0 through 9, with 6 as the default. Level 0 uses stored blocks. The variation above selects level 9 and demonstrates a deliberately small decompression ceiling.
The encoder documentation explains the level choices. A higher level is not permission to omit the decode limit: encoder settings and decompression resource limits solve different problems. The full program checks equality of the restored bytes, not the file extension or whether the decoded bytes happen to be valid text.
Decompress returns the whole decoded byte array. Its output limit defaults to 1 GiB, but an application expecting a small message should set a smaller ceiling. Here the short snippet uses 1024 bytes for a 16-byte message. For larger streaming workflows, the package also exposes incremental encoder and decoder APIs; the one-call example is appropriate when retaining both input and output in memory is acceptable.
Is Deflate64 the same as Deflate in a ZIP file?
No. The decoder documentation identifies raw Deflate64 as the data used by ZIP method 9. Deflate64 changes Deflate’s length and distance codes and uses a larger history window; the formats aren’t interchangeable.
There is no ZIP header, directory or checksum around the output of Deflate64.Compress. Renaming message.deflate64 to .zip would not create an archive. In a ZIP container, the ZIP layer supplies metadata and checks CRC-32; the raw codec has no checksum of its own. The program’s byte comparison confirms this particular round trip but does not add a checksum to the saved stream.
The decoder reads one stream. By default the one-call API refuses bytes after its end, as well as malformed or truncated input. AllowTrailingData changes the trailing-byte policy, not the compression format. Keep the strict default for a file expected to contain exactly one raw stream; if your application stores several messages together, define their framing explicitly rather than assuming a filename supplies boundaries.