9.1.0.12
libbrotli
| (require libbrotli) | package: libbrotli |
Racket bindings to Google’s Brotli compression library.
1 One-Shot Compression
procedure
(brotli-compress src [ quality #:window window #:mode mode #:lgblock lgblock #:dictionary dictionary]) → bytes? src : bytes? quality : quality/c = BROTLI_DEFAULT_QUALITY window : window/c = BROTLI_DEFAULT_WINDOW mode : mode/c = BROTLI_MODE_GENERIC lgblock : lgblock/c = 0 dictionary : bytes? = #""
Compresses src and returns the compressed bytes.
(require libbrotli) (define compressed (brotli-compress #"hello world")) (brotli-decompress compressed)
procedure
(brotli-decompress src [ max-decompressed-size #:dictionary dictionary]) → bytes? src : bytes? max-decompressed-size : (or/c #f exact-positive-integer?) = #f dictionary : bytes? = #""
Decompresses src and returns the original bytes. If
max-decompressed-size is not #f, limits the output size to
prevent decompression bombs.
value
Integer in the range 0 to 11.
value
Default compression quality for one-shot functions.
value
Minimum compression quality (fastest, lowest ratio).
value
Maximum compression quality (slowest, highest ratio).
value
Integer in the range 10 to 24.
value
Default sliding window size in bits.
value
Minimum window size (1 KB).
value
Maximum window size (16 MB).
value
value
Default compression mode. Works for any input.
value
Compression mode optimized for UTF-8 text.
value
Compression mode optimized for WOFF 2.0 fonts.
value
Either 0 (automatic) or an integer in the range 16 to
24.
2 Buffer Compression
procedure
(brotli-compress! src dst [ quality #:window window #:mode mode #:lgblock lgblock #:dictionary dictionary]) → exact-nonnegative-integer? src : bytes? dst : bytes? quality : quality/c = BROTLI_DEFAULT_QUALITY window : window/c = BROTLI_DEFAULT_WINDOW mode : mode/c = BROTLI_MODE_GENERIC lgblock : lgblock/c = 0 dictionary : bytes? = #""
Compresses src into the pre-allocated buffer dst. Returns the
number of bytes written. Raises an error if dst is too small.
procedure
(brotli-decompress! src dst [ #:dictionary dictionary]) → exact-nonnegative-integer? src : bytes? dst : bytes? dictionary : bytes? = #""
Decompresses src into the pre-allocated buffer dst. Returns the
number of bytes written. Raises an error if dst is too small.
3 Streaming Ports
procedure
(open-brotli-output out [ #:quality quality #:window window #:mode mode #:lgblock lgblock #:dictionary dictionary #:close? close? #:name name]) → output-port? out : output-port? quality : quality/c = 6 window : window/c = BROTLI_DEFAULT_WINDOW mode : mode/c = BROTLI_MODE_GENERIC lgblock : lgblock/c = 0 dictionary : bytes? = #"" close? : boolean? = #t name : symbol? = 'brotli-output
Returns an output port that compresses data written to it and forwards the
compressed bytes to out. Closing the returned port flushes the
remaining compressed data. If close? is #t, closing also
closes out.
Note: the default quality for streaming is 6 (not 11), which is a better tradeoff for real-time use.
(require libbrotli) (define out (open-output-bytes)) (define brotli-out (open-brotli-output out)) (write-bytes #"hello world" brotli-out) (close-output-port brotli-out) (brotli-decompress (get-output-bytes out))
procedure
(open-brotli-input in [ #:dictionary dictionary #:close? close? #:name name]) → input-port? in : input-port? dictionary : bytes? = #"" close? : boolean? = #t name : symbol? = 'brotli-input
Returns an input port that decompresses Brotli-encoded data read from
in. If close? is #t, closing the returned port also
closes in.