Module std::encoding::compress

Compression 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.

Examples

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
}

Contents

Functions

Function gzip_compress

pub fn gzip_compress(data: bytes) -> Result<bytes, string>

Gzip-compress data without panicking.

Returns Err(reason) on codec failure and Ok(data) on success. Empty output alone does not indicate failure.

Function gzip_decompress

pub fn gzip_decompress(data: bytes, max_output_len: i64) -> Result<bytes, string>

Gzip-decompress data without panicking.

Function deflate_compress

pub fn deflate_compress(data: bytes) -> Result<bytes, string>

Deflate-compress data (raw DEFLATE) without panicking.

Function deflate_decompress

pub fn deflate_decompress(data: bytes, max_output_len: i64) -> Result<bytes, string>

Deflate-decompress data (raw DEFLATE) without panicking.

Function zlib_compress

pub fn zlib_compress(data: bytes) -> Result<bytes, string>

Zlib-compress data without panicking.

Function zlib_decompress

pub fn zlib_decompress(data: bytes, max_output_len: i64) -> Result<bytes, string>

Zlib-decompress data without panicking.