Skip to main content

Crate autozstd

Crate autozstd 

Source
Expand description

Zstd envelope compression with automatic raw fallback.

An envelope is [type][payload]: the first byte is a Type, and the payload is either the input unchanged or a magicless Zstandard frame.

encode skips inputs shorter than 7 bytes and known compressed formats directly, and probes inputs of 128 KiB and up before a full compression pass. Whenever the compressed frame is not smaller than the input, raw bytes are stored instead.

Encoder and decoder contexts are reused per thread across calls. Use decode_limit when decoding untrusted inputs to bound the decompressed size.

encode_owned keeps the input allocation for raw payloads and returns the tag separately as Encoded, while encode_into writes into a caller-provided buffer. decode_owned shifts a raw payload over its tag without allocating.

The optional adaptive feature adds Adaptive, which folds measured compression speed and ratio into a network-aware level choice.

use autozstd::{Level, decode, encode};

let data = b"hello world ".repeat(100);
let packed = encode(&data, Level::Balanced);
assert_eq!(decode(&packed)?, data);

Structs§

Adaptiveadaptive
Network-aware level chooser that learns from previous calls.
Encoded
Encoded payload with the type tag kept separate from the payload buffer.
Statadaptive
Estimated behavior of one level.

Enums§

Choiceadaptive
Chosen compression mode.
Error
Errors returned when decoding an envelope.
Level
Compression level presets.
Type
Payload kind, stored in the first byte of an envelope.

Functions§

decode
Decodes an envelope produced by encode.
decode_limit
Decodes an envelope produced by encode, rejecting any payload whose decoded size exceeds max_len bytes.
decode_owned
Decodes an owned envelope, reusing its buffer for raw payloads.
decode_owned_limit
Decodes an owned envelope, rejecting any payload whose decoded size exceeds max_len bytes.
encode
Compresses data into an envelope.
encode_into
Encodes into out, reusing its capacity, and returns the payload kind.
encode_owned
Encodes an owned buffer, keeping it unchanged when raw bytes are chosen.

Type Aliases§

Result
Result alias with Error.