Brotli compression for HTTP responses and SSE streams.
Provides both one-shot compression (for page responses, via middleware) and streaming compression (for SSE connections where the LZ77 window is maintained across chunks for better ratios).
Brotli compression for HTTP responses and SSE streams. Provides both one-shot compression (for page responses, via middleware) and streaming compression (for SSE connections where the LZ77 window is maintained across chunks for better ratios).
(accepts-br? req)Check if the request's Accept-Encoding header includes brotli.
Check if the request's Accept-Encoding header includes brotli.
(byte-array-out-stream)Create a ByteArrayOutputStream for use with compress-out-stream.
Create a ByteArrayOutputStream for use with compress-out-stream.
(close-stream br)Close the brotli output stream. Safe to call on nil.
Close the brotli output stream. Safe to call on nil.
(compress data & {:as opts})One-shot compress a string or byte array. Returns a byte array. Suitable for full page responses where max compression is preferred.
One-shot compress a string or byte array. Returns a byte array. Suitable for full page responses where max compression is preferred.
(compress-out-stream out-stream & {:as opts})Create a BrotliOutputStream wrapping a ByteArrayOutputStream. Used for streaming compression where the LZ77 window is maintained across multiple chunks (e.g. SSE events).
Create a BrotliOutputStream wrapping a ByteArrayOutputStream. Used for streaming compression where the LZ77 window is maintained across multiple chunks (e.g. SSE events).
(compress-stream out br chunk)Write a string chunk into a streaming brotli compressor, flush, and return the compressed bytes. Resets the underlying ByteArrayOutputStream so the next call only returns newly compressed data.
The BrotliOutputStream maintains its LZ77 window across calls, giving better compression ratios for repeated SSE fragments.
Write a string chunk into a streaming brotli compressor, flush, and return the compressed bytes. Resets the underlying ByteArrayOutputStream so the next call only returns newly compressed data. The BrotliOutputStream maintains its LZ77 window across calls, giving better compression ratios for repeated SSE fragments.
(decompress data)Decompress a complete brotli-compressed byte array back to a UTF-8 string.
Decompress a complete brotli-compressed byte array back to a UTF-8 string.
(decompress-stream data)Decompress brotli data that may be an incomplete stream (e.g. flushed streaming chunks that lack a final block).
Decompress brotli data that may be an incomplete stream (e.g. flushed streaming chunks that lack a final block).
(encoder-params {:keys [quality window-size]})Build encoder parameters. quality: 0-11 (default 5 for streaming, 11 for static) window-size: 0 or 10-24 (default 24)
Build encoder parameters. quality: 0-11 (default 5 for streaming, 11 for static) window-size: 0 or 10-24 (default 24)
(wrap-brotli handler)Ring middleware that compresses response bodies with brotli. Only compresses when:
Uses quality 11 (max) for one-shot responses since they're not latency-sensitive like streaming SSE.
Ring middleware that compresses response bodies with brotli. Only compresses when: - Client sends Accept-Encoding: br - Response body is a string (typical for HTML/JSON) - Response is not already encoded Uses quality 11 (max) for one-shot responses since they're not latency-sensitive like streaming SSE.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |