compress
compress
Section titled “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).
Import
Section titled “Import”use std::core::compresscompress::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"Zstandard
Section titled “Zstandard”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 compressioncompress::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)Raw Deflate
Section titled “Raw Deflate”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.
Example: Roundtrip
Section titled “Example: Roundtrip”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 == textSee Also
Section titled “See Also”- archive — archive creation and extraction