brotli
-std.brotli — Brotli compression (RFC 7932), streaming and one-shot.
+std.brotli — Brotli (RFC 7932) encoding and decoding, streaming and one-shot.
import std.brotli
release_decompress_stream extern
available fn
available() -> int
- 1 when the toolchain was built with libbrotlienc detected. Use it to skip a test or pick a fallback encoding rather than threading an error everywhere.
+ 1 when the toolchain was built with libbrotli detected. Use it to skip a test or pick a fallback encoding rather than threading an error everywhere.
+
available() -> intdecoder_available fn
+decoder_available() -> int
+ 1 when decoding works here: brotli is built in AND the system libbrotlidec carries the CVE-2026-111497 fix (an out-of-bounds write on malformed input, libbrotli 1.0.3 to 1.2.0). Without the fix every decode refuses with an error rather than run a decoder that untrusted input can exploit; encoding is unaffected. The check asks the library itself, so a distro backport that keeps the old version number passes.
compress fn
@@ -238,13 +244,13 @@compress fn
decompress fn
decompress(data)
data: byte[]
-One-shot: decompress brotli-encoded data. Returns (bytes, count, "") on success, ("", 0, error) otherwise.
+One-shot: decompress with the default 1 GiB ceiling. Returns (bytes, count, "") on success, ("", 0, error) otherwise. For input you did not produce, use decompress_max with a cap that fits the job.
decompress_max fn
decompress_max(data, max_bytes)
data: byte[], max_bytes: int
-One-shot decompress with a strict output limit (`max_bytes`). If output would exceed `max_bytes`, decoding is aborted and returns an error mitigating decompression bomb attack vectors (e.g. broccoli2shell / CVE-2026-111497).
+One-shot with a cap: decoding stops, and returns an "output limit exceeded" error, as soon as the output would pass `max_bytes` (0 = the 1 GiB ceiling). Truncated input, corrupt input and bytes after the end of the stream are errors too.
stream_new fn
@@ -280,25 +286,25 @@stream_free fn
decompress_stream_new fn
decompress_stream_new(max_bytes) -> (ptr, string)
max_bytes: int
-Streaming decompression. `max_bytes` sets a strict cumulative output upper bound across stream lifetime (0 = default safety ceiling).
+Open a decoding stream whose total output is capped at `max_bytes` (0 = the 1 GiB ceiling). Returns (handle, "") or (null, error).
decompress_stream_write fn
decompress_stream_write(handle, data)
handle: ptr, data: byte[]
-Feed bytes into a decompression stream. Returns (decompressed_chunk, count, "").
+Feed compressed bytes in any size of chunk. Returns (bytes, count, "") with whatever they decoded to. After an error the handle refuses further writes.
decompress_stream_finish fn
decompress_stream_finish(handle) -> (string, int, string)
handle: ptr
-Finish a decompression stream and flush any final decompressed bytes.
+Confirm the stream ended. Returns ("", 0, "") when it did, and a "truncated stream" error when the input stopped short of the end, so a cut connection is not mistaken for a shorter body. Still needs decompress_stream_free.
decompress_stream_free fn
decompress_stream_free(handle)
handle: ptr
-Release a decompression stream handle. Safe on null.
+Release a decoding stream. Safe on null.
MIN_QUALITY const
diff --git a/docs/api/index.html b/docs/api/index.html index b14735ed0..4469d85b4 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -148,8 +148,8 @@bits
brotli
-std.brotli — Brotli compression (RFC 7932), streaming and one-shot.
- 33 exports +std.brotli — Brotli (RFC 7932) encoding and decoding, streaming and one-shot.
+ 34 exports