Skip to content

compress

The compress module provides data compression and decompression using gzip, Zstandard (zstd), and raw deflate. Compressed data is represented as Array<int> byte arrays (each element 0-255).

use std::core::compress

compress::gzip(data: string) -> Array<int>

Section titled “compress::gzip(data: string) -> Array<int>”

Compress a string using gzip, returning a byte array.

let compressed = compress::gzip("hello world")

compress::gunzip(data: Array<int>) -> string

Section titled “compress::gunzip(data: Array<int>) -> string”

Decompress a gzip byte array back to a string.

let original = compress::gunzip(compressed)
// "hello world"

compress::zstd(data: string, level: int) -> Array<int>

Section titled “compress::zstd(data: string, level: int) -> Array<int>”

Compress a string using Zstandard. The level parameter controls compression strength (typical: 1 = fast, 3 = balanced, 22 = max).

let compressed = compress::zstd("hello zstd", 1) // fast compression

compress::unzstd(data: Array<int>) -> string

Section titled “compress::unzstd(data: Array<int>) -> string”

Decompress a Zstandard byte array back to a string.

let original = compress::unzstd(compressed)

compress::deflate(data: string) -> Array<int>

Section titled “compress::deflate(data: string) -> Array<int>”

Compress a string using raw deflate (no gzip/zlib headers), returning a byte array.

compress::inflate(data: Array<int>) -> string

Section titled “compress::inflate(data: Array<int>) -> string”

Decompress a raw deflate byte array back to a string.

use std::core::compress
let text = "The quick brown fox jumps over the lazy dog"
let compressed = compress::gzip(text)
let decompressed = compress::gunzip(compressed)
assert decompressed == text
  • archive — archive creation and extraction