Type: | Package |
Title: | DEFLATE Compression and Static Library |
Version: | 1.24-7 |
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'. |
Depends: | R (≥ 3.5.0) |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
SystemRequirements: | GNU make, CMake |
RoxygenNote: | 7.3.2 |
Config/build/compilation-database: | true |
BugReports: | https://github.com/tylermorganwall/libdeflate/issues |
NeedsCompilation: | yes |
Packaged: | 2025-07-17 02:06:33 UTC; tyler |
Author: | Tyler Morgan-Wall |
Maintainer: | Tyler Morgan-Wall <tylermw@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-07-21 13:51:57 UTC |
Allocate a libdeflate compressor
Description
Create a new libdeflate compressor at the specified compression level.
Usage
alloc_compressor(level = 6L)
Arguments
level |
Default '6L'. Integer in [0, 12] giving the compression level (0 = no compression, 1 = fastest, 6 = default, 12 = slowest). |
Value
An external pointer ('externalptr') to a libdeflate compressor.
See Also
[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))
Allocate a libdeflate decompressor
Description
Create a new libdeflate decompressor for raw DEFLATE streams.
Usage
alloc_decompressor()
Value
An external pointer ('externalptr') to a libdeflate decompressor.
Examples
dcmp = alloc_decompressor()
stopifnot(inherits(dcmp, "externalptr"))
Compress a raw vector with libdeflate
Description
Compress the given raw vector using the specified libdeflate compressor.
Usage
deflate_compress(compressor, input)
Arguments
compressor |
An external pointer created by 'alloc_compressor()'. |
input |
A raw vector (or object coercible to raw) containing the data to compress. |
Value
A raw vector containing the DEFLATE‐compressed output.
Examples
# 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 vector with libdeflate
Description
Decompress a raw DEFLATE stream to its original length.
Usage
deflate_decompress(decompressor, input, out_len)
Arguments
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). |
Value
A raw vector of length 'out_len' containing the decompressed data.
Examples
# 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))