@std/compress.ms#
Import each required symbol with import Name from "@std/compress.ms".
CompressionError Alternative#
Errors returned when compressed data is unsupported, invalid, or exceeds a limit.
type CompressionError:
case InvalidInput
case InvalidData
case LimitExceeded
case Unsupported
case Failed(message: String)impl Error for CompressionError:
fn message() -> String:CompressionError.Failed#
An explicit implementation-supplied compression diagnostic; native codecs use specific cases.
case Failed(message: String)CompressionError.InvalidData#
Compressed framing, checksum, payload or trailing data is invalid for the chosen format.
case InvalidDataCompressionError.InvalidInput#
Compression level is outside 0..9, or a supplied encoded/decoded byte budget is negative.
case InvalidInputCompressionError.LimitExceeded#
Encoded or decompressed output exceeds the supplied byte budget.
case LimitExceededCompressionError.Unsupported#
A String selector is not exactly gzip, zlib or deflate; typed selectors avoid spelling errors.
case UnsupportedCompressionError.Failed.message#
Original diagnostic text, returned unchanged by message().
message: StringCompressionError.Error.message#
Returns original Failed text, or a compression-prefixed diagnostic for other cases.
fn message() -> String:CompressionFormat Alternative#
Selects a supported compression format; Deflate is raw DEFLATE without a wrapper. Existing compress/decompress format: String calls remain available.
type CompressionFormat:
case Gzip
case Zlib
case Deflate
fn compress(data: Bytes, level: Int = 6, max_bytes: Optional[Int] = none) -> Result[Bytes, CompressionError]:
fn decompress(data: Bytes, max_bytes: Optional[Int] = none) -> Result[Bytes, CompressionError]:CompressionFormat.Deflate#
Raw DEFLATE without framing.
case DeflateCompressionFormat.Gzip#
DEFLATE data wrapped in GZIP headers and a checksum trailer.
case GzipCompressionFormat.Zlib#
DEFLATE data with ZLIB header and Adler-32 checksum framing.
case ZlibCompressionFormat.compress#
Compresses with level 6 by default; explicit levels remain 0..9 (0 stores data). Uses the same optional output budget/domain errors as compress.
fn compress(data: Bytes, level: Int = 6, max_bytes: Optional[Int] = none) -> Result[Bytes, CompressionError]:CompressionFormat.decompress#
Decompresses with the same cumulative output limit and validation as decompress.
fn decompress(data: Bytes, max_bytes: Optional[Int] = none) -> Result[Bytes, CompressionError]:compress Function#
Compresses using exactly gzip, zlib, or raw deflate (case-sensitive).
Other formats return Unsupported; level defaults to 6 (balanced DEFLATE compression).
Explicit levels must be 0..9 (0 stores data), else InvalidInput.
max_bytes bounds the encoded output when supplied.
fn compress(data: Bytes, format: String, level: Int = 6, max_bytes: Optional[Int] = none) -> Result[Bytes, CompressionError]:decompress Function#
Decompresses exactly gzip, zlib, or raw deflate (case-sensitive); others return Unsupported.
Stops when the supplied output limit is reached.
fn decompress(data: Bytes, format: String, max_bytes: Optional[Int] = none) -> Result[Bytes, CompressionError]: