xz: Compressing and uncompressing text files

Description Usage Arguments Value Author(s) Examples

Description

These functions are adapted from the R.utils package from gzip to xz. Internally xzfile() (see connections) is used to read (write) chunks to (from) the xz file. If the process is interrupted before completed, the partially written output file is automatically removed.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
xzcompress(
  filename,
  destname = sprintf("%s.xz", filename),
  temporary = FALSE,
  skip = FALSE,
  overwrite = FALSE,
  remove = TRUE,
  BFR.SIZE = 1e+07,
  compression = 6,
  ...
)

xzuncompress(
  filename,
  destname = gsub("[.]xz$", "", filename, ignore.case = TRUE),
  temporary = FALSE,
  skip = FALSE,
  overwrite = FALSE,
  remove = TRUE,
  BFR.SIZE = 1e+07,
  ...
)

Arguments

filename

Path name of input file.

destname

Pathname of output file.

temporary

If TRUE, the output file is created in a temporary directory.

skip

If TRUE and the output file already exists, the output file is returned as is.

overwrite

If TRUE and the output file already exists, the file is silently overwritting, otherwise an exception is thrown (unless skip is TRUE).

remove

If TRUE, the input file is removed afterward, otherwise not.

BFR.SIZE

The number of bytes read in each chunk.

compression

The compression level used (1-9).

...

Not used.

Value

Returns the pathname of the output file. The number of bytes processed is returned as an attribute.

Author(s)

Kristian Hovde Liland.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Creating small file
tf <- tempfile()
cat(file=tf, "Hello world!")

# Compressing
tf.xz <- xzcompress(tf)
print(file.info(tf.xz))

# Uncompressing
tf <- xzuncompress(tf.xz)
print(file.info(tf))
file.remove(tf)

micropan documentation built on July 15, 2020, 5:08 p.m.