| Title: | DEFLATE Compression and Static Library |
|---|---|
| Description: | Whole-buffer DEFLATE-based compression and decompression of raw vectors using the 'libdeflate' library (see <https://github.com/ebiggers/libdeflate>). Provides the user with additional control over the speed and the quality of DEFLATE compression compared to the fixed level of compression offered in R's 'memCompress()' function. Also provides the 'libdeflate' static library and 'C' headers along with a 'CMake' target and 'package‑config' file that ease linking of 'libdeflate' in packages that compile and statically link bundled libraries using 'CMake'. |
| Authors: | Tyler Morgan-Wall [aut, cre] (ORCID: <https://orcid.org/0000-0002-3131-3814>), Eric Biggers [aut, cph], Google LLC [cph], Kevin Ushey [cph] |
| Maintainer: | Tyler Morgan-Wall <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.25-0 |
| Built: | 2026-05-22 08:15:49 UTC |
| Source: | https://github.com/tylermorganwall/libdeflate |
Create a new libdeflate compressor at the specified compression level.
alloc_compressor(level = 6L)alloc_compressor(level = 6L)
level |
Default '6L'. Integer in [0, 12] giving the compression level (0 = no compression, 1 = fastest, 6 = default, 12 = slowest). |
An external pointer ('externalptr') to a libdeflate compressor.
[base::memDecompress()] also provides DEFLATE compression via libdeflate, but it fixes the compression level at 6. # allocate a compressor and compress a simple string cmp = alloc_compressor() raw_in = charToRaw("Example data") raw_cmp = deflate_compress(cmp, raw_in) stopifnot(is.raw(raw_cmp))
Create a new libdeflate decompressor for raw DEFLATE streams.
alloc_decompressor()alloc_decompressor()
An external pointer ('externalptr') to a libdeflate decompressor.
dcmp = alloc_decompressor() stopifnot(inherits(dcmp, "externalptr"))dcmp = alloc_decompressor() stopifnot(inherits(dcmp, "externalptr"))
Compress the given raw vector using the specified libdeflate compressor.
deflate_compress(compressor, input)deflate_compress(compressor, input)
compressor |
An external pointer created by 'alloc_compressor()'. |
input |
A raw vector (or object coercible to raw) containing the data to compress. |
A raw vector containing the DEFLATE‐compressed output.
# Low compression values might not compress at all cmp = alloc_compressor(1L) raw_in = charToRaw("Fast compression test: 1231231231231231") raw_cmp_1 = deflate_compress(cmp, raw_in) print(sprintf("Length in: %i Length out: %i", length(raw_in), length(raw_cmp_1) )) # Max compression is 12 cmp = alloc_compressor(12L) raw_cmp_12 = deflate_compress(cmp, raw_in) print(sprintf("Length in: %i Length out: %i", length(raw_in), length(raw_cmp_12) ))# Low compression values might not compress at all cmp = alloc_compressor(1L) raw_in = charToRaw("Fast compression test: 1231231231231231") raw_cmp_1 = deflate_compress(cmp, raw_in) print(sprintf("Length in: %i Length out: %i", length(raw_in), length(raw_cmp_1) )) # Max compression is 12 cmp = alloc_compressor(12L) raw_cmp_12 = deflate_compress(cmp, raw_in) print(sprintf("Length in: %i Length out: %i", length(raw_in), length(raw_cmp_12) ))
Decompress a raw DEFLATE stream to its original length.
deflate_decompress(decompressor, input, out_len)deflate_decompress(decompressor, input, out_len)
decompressor |
An external pointer created by 'alloc_decompressor()'. |
input |
A raw vector containing the compressed DEFLATE stream. |
out_len |
Integer giving the expected uncompressed length (in bytes). |
A raw vector of length 'out_len' containing the decompressed data.
# round-trip example msg = "Round-trip test: 123123123123" raw_in = charToRaw(msg) cmp = alloc_compressor(12L) raw_cmp = deflate_compress(cmp, raw_in) dcmp = alloc_decompressor() raw_out = deflate_decompress(dcmp, raw_cmp, length(raw_in)) stopifnot(identical(raw_out, raw_in))# round-trip example msg = "Round-trip test: 123123123123" raw_in = charToRaw(msg) cmp = alloc_compressor(12L) raw_cmp = deflate_compress(cmp, raw_in) dcmp = alloc_decompressor() raw_out = deflate_decompress(dcmp, raw_cmp, length(raw_in)) stopifnot(identical(raw_out, raw_in))