brotli | R Documentation |
Brotli is a compression algorithm optimized for the web, in particular small text documents.
brotli_compress(buf, quality = 11, window = 22)
brotli_decompress(buf)
buf |
raw vector with data to compress/decompress |
quality |
value between 0 and 11 |
window |
log of window size |
Brotli decompression is at least as fast as for gzip while significantly improving the compression ratio. The price we pay is that compression is much slower than gzip. Brotli is therefore most effective for serving static content such as fonts and html pages.
For binary (non-text) data, the compression ratio of Brotli usually does not beat
bz2
or xz (lzma)
, however decompression for these algorithms is too
slow for browsers in e.g. mobile devices.
J. Alakuijala and Z. Szabadka (July 2016). Brotli Compressed Data Format. IETF Internet Draft https://www.rfc-editor.org/rfc/rfc7932.
memCompress
# Simple example
myfile <- file.path(R.home(), "COPYING")
x <- readBin(myfile, raw(), file.info(myfile)$size)
y <- brotli_compress(x)
stopifnot(identical(x, brotli_decompress(y)))
# Compare to other algorithms
length(x)
length(brotli_compress(x))
length(memCompress(x, "gzip"))
length(memCompress(x, "bzip2"))
length(memCompress(x, "xz"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.