Recursive AI

gzip that other tools read

All onearchive recipes

Compress with OneCompress’s gzip and read it with .NET’s GZipStream, and the other way round: the formats are the standard ones, byte for byte.

This recipe uses the Deflate family, so it opts in to ONECOMPRESS003 as well:

XML
<NoWarn>$(NoWarn);ONECOMPRESS001;ONECOMPRESS003;ONEARCHIVE001</NoWarn>
C#
using System.IO.Compression;
using System.Text;
using RecursiveAI.OneCompress.Checksums;
using RecursiveAI.OneCompress.Deflate;
 
byte[] log = Encoding.UTF8.GetBytes(string.Concat(Enumerable.Range(0, 5000).Select(i => $"2026-10-30T12:{i % 60:D2}:00Z GET /api/items/{i % 97} 200\n")));
 
// OneCompress writes gzip; System.IO.Compression reads it.
byte[] gz = GZip.Compress(log, new DeflateOptions { Level = 9 });
using (var input = new GZipStream(new MemoryStream(gz), CompressionMode.Decompress))
using (var output = new MemoryStream())
{
    input.CopyTo(output);
    Console.WriteLine($"gzip level 9: {log.Length:N0} -> {gz.Length:N0} bytes; GZipStream reads it back: {output.ToArray().AsSpan().SequenceEqual(log)}");
}
 
// And the other way round.
var net = new MemoryStream();
using (var w = new GZipStream(net, CompressionLevel.SmallestSize, leaveOpen: true)) w.Write(log);
Console.WriteLine($"GZipStream output read by OneCompress: {GZip.Decompress(net.ToArray()).AsSpan().SequenceEqual(log)}");
 
// The same bytes on every machine: hash the compressed output to check.
Console.WriteLine($"CRC32 of the gzip bytes: {Crc32.Compute(gz):X8}");
Text
gzip level 9: 214,480 -> 16,205 bytes; GZipStream reads it back: True
GZipStream output read by OneCompress: True
CRC32 of the gzip bytes: BF755A76

Good to know

  • GZip, ZLib and Deflate take DeflateOptions: levels 0 to 12, strategies, preset dictionaries and flushes.
  • The compressed bytes are the same on every platform, so a CRC32 or SHA-256 of the output is a valid cache key or test fixture. RecursiveAI.OneCompress.Checksums also has CRC32C, CRC64, Adler-32 and xxHash64.

Encoder choices and speeds are in the Deflate encoder and checksums.