archive_open() returns a handle over a ZIP, tar or Compound File
archive, held as a path or as a raw vector in memory. The format comes
from the bytes, never from the file name.
Usage
archive_open(x, format = NULL, limits = archive_limits())Arguments
- x
A path to an archive (a single string), or a raw vector holding one.
- format
NULLto detect the format from the bytes, or one of"zip","tar"or"cfb"to read the archive as that format. A given format must not contradict the bytes; it is needed for input whose format has no magic number, such as a tar written before POSIX ustar.- limits
The limits the readers enforce, from
archive_limits().
Details
A handle over a raw vector keeps that vector alive for as long as the handle exists, so the caller may drop its own reference. Changing the caller's copy afterwards does not change the bytes the handle reads.
A handle over a path holds no open file between calls: each use opens the
path again, so the handle survives a change of working directory (the path
is made absolute at open) and sees the file as it is when used. If the
file has gone, using the handle raises zuarchive_error_not_found; if it
now holds a different format, zuarchive_error_format.
A handle cannot be saved: one restored by readRDS() or unserialize()
raises zuarchive_error when used. Open the archive again instead.
Conditions
Each refusal is an error of class zuarchive_error and a subclass:
zuarchive_error_path:xis neither a single path nor a raw vector, isNAor empty, or names a directory.zuarchive_error_not_found: the path does not exist or cannot be read.zuarchive_error_format: the bytes are of no format zuarchive reads,formatis not one of the three, orformatcontradicts the bytes.zuarchive_error_limit:limitswas not made byarchive_limits().
Examples
# An empty ZIP archive is its end-of-central-directory record alone.
empty_zip <- as.raw(c(0x50, 0x4b, 0x05, 0x06, rep(0, 18)))
z <- archive_open(empty_zip)
z
#> <zuarchive_handle: zip, 22 bytes in memory>
archive_format(z)
#> [1] "zip"