lzCompress: lzCompress In-memory Compression and Decompression

Description Usage Arguments Value Note See Also Examples

View source: R/functions.R

Description

In-memory compression or decompression for raw vectors, cf. memCompress.

Usage

1
2
3
lzCompress(from, level = 0L, type)

lzDecompress(from, type)

Arguments

from

A raw or character vector to be compressed (for lzCompress), or a raw vector to be decompressed (for lzDecompress). Character vectors will be converted to raw vectors with character strings separated by "\n" in the lzCompress case.

level

An integer between 0 (fast but less compression) and 9 (slow but more compression), inclusive.

type

Not used! This dummy argument is present to facilitate drop-in replacement with memCompress. We reserve the parameter name for future use however, but right now it is ignored.

Value

A raw vector representing the compressed object.

Note

The functions are compatible with the command-line lz4 format for easy interoparability with other applications. See the examples.

See Also

memCompress, memDecompress

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
x <- head(airquality)
y <- lzCompress(serialize(x, NULL))
z <- unserialize(lzDecompress(y))
all.equal(x, z)

## Not run: 
# Compatibility with the lz4 file format, this example assumes that
# the 'lz4' program is in your system PATH.
# Compress some text in R and save to a file:
compressed_file <- tempfile()
writeBin(lzCompress(capture.output(head(state.x77))), compressed_file)

# Now decompress those data with command-line lz, saving to another file:
decompressed_file <- tempfile()
system2("lz4", args=c("-d", compressed_file, decompressed_file))

# Examine the output:
readLines(decompressed_file, warn=FALSE)

## End(Not run)

bwlewis/lz4 documentation built on Dec. 27, 2020, 11:07 a.m.