std::encoding::compressCompression and decompression (gzip, deflate, zlib).
Compress and decompress binary data using gzip, raw deflate, or
zlib formats. Compression helpers take bytes and return
Result<bytes, string> so codec failures can be handled explicitly.
Decompression callers must pass an explicit max_output_len to fail
closed on oversized payloads; a conservative starting point is
64 * 1024 * 1024.
import std.encoding.compress;
fn main() {
var data: bytes = bytes.new();
data.push(72);
data.push(101);
data.push(108);
data.push(108);
data.push(111);
let compressed = compress.gzip_compress(data) handle error {
println(f"operation failed: {error}");
return;
};
let decompressed = compress.gzip_decompress(compressed, 64 * 1024 * 1024) handle error {
println(f"operation failed: {error}");
return;
};
println(decompressed.len()); // 5
}
gzip_compressGzip-compress data without panicking.
Returns Err(reason) on codec failure and Ok(data) on success.
Empty output alone does not indicate failure.
gzip_decompressGzip-decompress data without panicking.
deflate_compressDeflate-compress data (raw DEFLATE) without panicking.
deflate_decompressDeflate-decompress data (raw DEFLATE) without panicking.
zlib_compressZlib-compress data without panicking.
zlib_decompressZlib-decompress data without panicking.