komp_compress: Compress a raw vector

View source: R/compress.R

komp_compressR Documentation

Compress a raw vector

Description

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.

Usage

komp_compress(x, codec = "gzip", level = NULL)

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", or NULL for the codec's own default.

Numeric levels are not comparable between codecs: 6 means different things to gzip and to zstd, and komp_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 (the level_fast and level_best columns), and they work on every codec, including ones with no level axis at all.

Value

A raw vector.

See Also

komp_decompress(), komp_codecs()

Examples

x <- charToRaw(strrep("compress me ", 100))
z <- komp_compress(x)
length(x)
length(z)
identical(komp_decompress(z, "gzip"), x)

# gzip output is deterministic: no timestamp, no filename
identical(komp_compress(x), komp_compress(x))

# abstract levels port across codecs; numeric ones do not
length(komp_compress(x, level = "fast"))
length(komp_compress(x, level = "best"))

zukomp documentation built on Oct. 16, 2026, 5:09 p.m.