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
get_compress_length extern
release_compress extern
release_compress()
release_compress()get_decompress_bytes extern
+get_decompress_bytes() -> ptr
+ get_decompress_length extern
+get_decompress_length() -> int
+ release_decompress extern
+release_decompress()
+ try_decompress_stream_new extern
+try_decompress_stream_new(max_bytes) -> ptr
+ max_bytes: int
+get_decompress_stream_bytes extern
+get_decompress_stream_bytes(handle) -> ptr
+ handle: ptr
+get_decompress_stream_length extern
+get_decompress_stream_length(handle) -> int
+ handle: ptr
+release_decompress_stream extern
+release_decompress_stream(handle)
+ handle: ptr
+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.
+decoder_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
@@ -189,6 +240,18 @@compress fn
data: byte[], quality: int
One-shot: compress a body already in memory. Returns (bytes, count, "") on success, ("", 0, error) otherwise. Quality out of range is clamped.
decompress fn
+decompress(data)
+ data: byte[]
+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 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
stream_new(quality, window) -> (ptr, string)
@@ -219,6 +282,30 @@ stream_free fn
handle: ptr
Release the handle. Safe on null.
decompress_stream_new fn
+decompress_stream_new(max_bytes) -> (ptr, string)
+ max_bytes: int
+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 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
+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 decoding stream. Safe on null.
+MIN_QUALITY const
MIN_QUALITY = 0
diff --git a/docs/api/index.html b/docs/api/index.html
index 19fea2194..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.
- 20 exports +std.brotli — Brotli (RFC 7932) encoding and decoding, streaming and one-shot.
+ 34 exports