decompress
decompress restores bytes produced by compress or by any other Gzip, zlib, raw Deflate, or Brotli implementation. Without format, it identifies Gzip and Deflate from their signatures; Brotli and raw Deflate have none and need format.
The limits are checked while the output is produced, never after, so a decompression bomb stops at the limit instead of filling the memory. maxRatio applies only after the first 1 MiB of output, since small inputs legitimately expand by large factors.
Signature
decompress(data: u8[], options?: DecompressOptions): Promise<Result<u8[], CompressError>>Minimal example
tyrus
import { CompressError, CompressFormat, compress, decompress } from "tyrus:compress";
async function restore(): Promise<Result<void, CompressError>> {
const packed: u8[] = await compress("Hello, Tyrus!", CompressFormat.Gzip)?;
const original: u8[] = await decompress(packed)?;
print(original.length); // 13
return Ok();
}Every option
tyrus
import { CompressError, CompressFormat, DecompressOptions, decompress } from "tyrus:compress";
async function restore(packed: u8[]): Promise<Result<void, CompressError>> {
const original: u8[] = await decompress(packed, {
format: CompressFormat.Brotli, // required for Brotli and DeflateRaw; default detected from the data
maxOutputBytes: 64_000_000, // refuse more output than this; default 256 MiB
maxRatio: 1_000, // refuse more than this expansion once past 1 MiB; default 200
})?;
print(original.length); // 13
return Ok();
}A format that does not match the data fails with ERR_COMPRESS_INVALID_DATA, and a limit of 0 fails with ERR_COMPRESS_INVALID_OPTION: options raise the limits, they never switch them off.
