Bytes in, bytes out. Character input is not accepted: encoding is a
decision the caller must make explicitly, so convert with
charToRaw() or iconv() first.
Arguments
- x
A raw vector.
- codec
Codec name, as listed in
komp_codecs(). Defaults to"gzip", which interoperates with everything.- level
Compression level. Either a codec-native whole number, one of the abstract names
"fast","default"and"best", orNULLfor the codec's own default.Numeric levels are not comparable between codecs:
6means different things to gzip and to zstd, andkomp_codecs()publishes each codec's valid range. The abstract names are therefore the portable way to say "compress harder" – each codec declares where"fast"and"best"land (thelevel_fastandlevel_bestcolumns), and they work on every codec, including ones with no level axis at all.
Examples
x <- charToRaw(strrep("compress me ", 100))
z <- komp_compress(x)
length(x)
#> [1] 1200
length(z)
#> [1] 50
identical(komp_decompress(z, "gzip"), x)
#> [1] TRUE
# gzip output is deterministic: no timestamp, no filename
identical(komp_compress(x), komp_compress(x))
#> [1] TRUE
# abstract levels port across codecs; numeric ones do not
length(komp_compress(x, level = "fast"))
#> [1] 50
length(komp_compress(x, level = "best"))
#> [1] 50