Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/compress/brotli"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
This package has no source imports.
Error
Enum · Source
pub enum Error {
// The input ended inside the stream.
Truncated,
// The stream is malformed.
InvalidData,
// The output buffer of decompress() cannot hold the decompressed data.
OutputFull,
// The Decoder window is shorter than the stream's sliding window and
// the decompressed data does not fit in it.
WindowTooSmall,
// The workspace cannot hold one meta-block's prefix code tables and
// context maps; WORKSPACE_LEN words always suffice.
WorkspaceTooSmall,
// Large-window Brotli.
Unsupported
}
WORKSPACE_LEN
Constant · Source
Workspace words that hold the tables of any valid meta-block: 256 literal, 256 insert-and-copy and 256 distance prefix codes at their largest two-level table sizes (632, 1080 and 920 words for 8-bit roots, the bounds libbrotli derives with zlib’s
enough), three block type and three block count codes (632 and 396 words), both context maps, the literal context modes, two directory words per code and 32 words for the temporary code length table.
pub const WORKSPACE_LEN: usize = 696108
STACK_WORKSPACE_LEN
Constant · Source
Workspace words decompress() and workspace_size() keep on the stack (16 KiB): enough for the streams the reference encoder writes for inputs of up to 128 KiB at any quality.
pub const STACK_WORKSPACE_LEN: usize = 8192
MAX_WINDOW_LEN
Constant · Source
The largest sliding window, for window size 24.
pub const MAX_WINDOW_LEN: usize = 16777216
MEASURE_LEN
Constant · Source
The largest single prefix code table (a 704-symbol insert-and-copy code); Decoder.workspace_needed() is exact for workspaces of at least this many words.
pub const MEASURE_LEN: usize = 1080
decompress
Function · Source
Decompresses one stream into output and returns its length. The output buffer is also the window, so no other memory is needed beyond 16 KiB of stack workspace (STACK_WORKSPACE_LEN words); a stream whose tables need more fails with WorkspaceTooSmall (see workspace_size and decompress_with_workspace). Input after the end of the stream is InvalidData. On error the output contents are unspecified. Not inlined, so callers do not carry its stack workspace.
@inline(never)
pub fn decompress(input: &[u8], output: &mut[u8]) -> usize!Error
decompress_with_workspace
Function · Source
decompress() with a caller-owned workspace, which may live in static storage: workspace_size(input) words decode the stream, WORKSPACE_LEN words every valid stream.
pub fn decompress_with_workspace(input: &[u8], output: &mut[u8], workspace: &mut[u16]) -> usize!Error
workspace_size
Function · Source
The workspace words needed to decode this stream, without decoding it: the headers are read and the tables built in STACK_WORKSPACE_LEN words of stack. Exact when the last compressed meta-block is the only one, or the earlier ones each fit in that stack workspace and choose literal trees without context modeling (such as the meta-blocks quality 0 and 1 write); otherwise WORKSPACE_LEN, which always suffices. Errors in the parts read are reported as decoding would. Not inlined, so callers do not carry its stack workspace.
@inline(never)
pub fn workspace_size(input: &[u8]) -> usize!Error
window_len
Function · Source
The window length a Decoder needs for this stream: the stream’s sliding window size (1 << WBITS, at most MAX_WINDOW_LEN), or the decompressed length when the stream holds a single meta-block that is shorter. Only the header is read.
pub fn window_len(input: &[u8]) -> usize!Error
decompressed_size
Function · Source
The decompressed length of a stream, found by decoding it through a window of window_len(input) or more bytes and discarding the data.
pub fn decompressed_size(input: &[u8], window: &mut[u8], workspace: &mut[u16]) -> usize!Error
Decoder
Struct · Source
Streaming Brotli decoder over a complete input. The caller’s window is a ring buffer of at least window_len(input) bytes (any length works when the decompressed data fits); read() fills output buffers of any size. The workspace holds the per-meta-block tables (see WORKSPACE_LEN). Errors are final.
pub struct Decoder {
// Private implementation fields omitted.
}
Decoder.new
Function · Source
Reads the stream header; fails with Unsupported for large-window streams.
pub fn new(input: &[u8], window: &mut[u8], workspace: &mut[u16]) -> Decoder!Error from(input, window, workspace)
Decoder.is_done
Function · Source
True once the whole stream has been decoded and read.
pub fn is_done(&self) -> bool
Decoder.input_consumed
Function · Source
Compressed bytes the stream occupies; meaningful once decoding has finished.
pub fn input_consumed(&self) -> usize
Decoder.produced
Function · Source
Decompressed bytes produced so far.
pub fn produced(&self) -> usize
Decoder.workspace_needed
Function · Source
Workspace words the meta-blocks read so far need: the largest of their table sets, so a workspace of this length decodes them all. After a WorkspaceTooSmall error it includes the meta-block that did not fit (exact when the workspace has MEASURE_LEN words or more).
pub fn workspace_needed(&self) -> usize
Decoder.read
Function · Source
Copies the next decompressed bytes to output and returns their count; 0 for a non-empty output means the stream has ended.
pub fn read(&mut self, output: &mut[u8]) -> usize!Error
Generated declarations in tables.dodo
tables.dodo holds 0 public declarations generated by scripts/gen. They follow the naming rules in the library guide; read the source file for exact signatures.