brotli {brotli} | R Documentation

## Brotli Compression

### Description

Brotli is a compression algorithm optimized for the web, in particular small text documents.

### Usage

    brotli_compress(buf, quality = 11, window = 22)

    brotli_decompress(buf)

### Arguments

`buf` | raw vector with data to compress/decompress
`quality` | value between 0 and 11
`window` | log of window size

### Details

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.

### References

J. Alakuijala and Z. Szabadka (July 2016). Brotli Compressed Data Format. IETF Internet Draft https://tools.ietf.org/html/rfc7932.

### See Also

memCompress

### Examples

    # 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"))

[Package brotli version 1.2 Index]