gzip: Perform in-memory gzip compression

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/compress.R

Description

This function compresses the content using the GZIP compression format and returns the resulting compressed content. It does this within memory rather than writing to file. This content can then be passed to other functions to be used in other contexts, e.g. sent to a Web server as part of a request, inserted into an HTML document via base64 encoding.

Usage

1
2
gzip(content, level = 1, windowBits = (15 + 16), memLevel = 9, strategy = 0L, 
      size = length(content) * 1.01 + 12)

Arguments

content

the content to be compressed. This should be either a raw vector or a character vector which will be collapsed to a single string.

level

the compression level, a number between 1 and 9

windowBits

integer between 24 and 31. Larger values result in better compression at the expense of memory usage. This is a value between 8 and 15 with 16 added on to cause GZIP compression to be used.

memLevel

a value between 1 and 9 that controls the tradeoff of memory and speed used in the process of compression. Larger values use more memory with better speed.

strategy

an integer, this should be 0 for the default strategy. filter, huffman and rle strategies are also available.

size

a number, the size to use as the best guess for the size of the result. The output buffer will grow as necessary, but this provides an opportunity to specify an initial guees.

Details

This uses the zlib library.

Value

A raw object containing the compressed information. Note that this cannot currently be uncompressed with the gunzip function but can be decompressed with the gzip application.

Author(s)

Duncan Temple Lang

References

http://www.gzip.org

See Also

compress

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
txt = paste(rep("This is a string", 40), collapse = "\n")
v = gzip(txt)
f = tempfile()
writeBin(v, f)
readLines(gzfile(f))


dev = paste(tempfile(), "pdf", sep = ".")
pdf(dev)
plot(1:10)
dev.off()
vals = readBinaryFile(dev)
writeBin(gzip(vals), paste(dev, "gz", sep = "."))

statwonk/Rcompression documentation built on May 30, 2019, 10:43 a.m.