archive_read() returns the bytes of one member, inflated and checked
against the member's CRC-32, as a raw vector or as a string.
Arguments
- z
A handle from
archive_open().- name
The member's name: a single string, compared with the members' names after conversion to UTF-8.
- as
"raw"for a raw vector, or"text"for a single string marked as UTF-8. Text must be well-formed UTF-8 without NUL bytes; it is returned byte for byte, a byte order mark included.
Details
The member is found by its exact name, as archive_list() shows it.
Before anything is inflated, the member is checked against the handle's
archive_limits() (max_member, max_ratio, and the archive-wide
limits archive_list() checks); while it is inflated, it may not grow
past the size the archive declares. A member that fails any check returns
nothing: the whole member is read and checked before a value is
returned.
A name that more than one member carries is refused: ZIP readers disagree on which of them it means, so zuarchive reads none.
In a Compound File, name is a stream's path as archive_list() shows
it, root entry first. A storage reads as raw(0). The format compares
names without regard to case, so two paths that differ only in the case
of ASCII letters are one name, and reading either is refused. The
stream's sector chain is checked whole before its first byte is read.
In a tar archive, a directory or a link reads as raw(0); a sparse
file or an "other" member raises zuarchive_error_format. A name
that more than one member carries is refused, as for ZIP.
Conditions
Every refusal is an error of class zuarchive_error and a subclass. Those
of archive_list(), and:
zuarchive_error_not_found: no member has that name.zuarchive_error_crc: the member's bytes do not match its CRC-32.zuarchive_error_malformed: the member's data is corrupt, ends early, does not decode to the declared size, or lies outside its bounds; or more than one member has that name. For a Compound File, the stream's sector chain is broken or shorter than its size.zuarchive_error_encrypted: the member is encrypted.zuarchive_error_format: the member is compressed with a method other than stored, DEFLATE or Zstandard (method 93), is a sparse or special tar member, or, foras = "text", is not UTF-8 text; orasis neither"raw"nor"text".zuarchive_error_limit:max_memberormax_ratiois exceeded.zuarchive_error_path:nameis not a single non-empty string.
The condition carries member, the name asked for.
See also
archive_stream() to read a large member in pieces,
archive_list()
Examples
z <- archive_open(system.file("extdata", "hello.zip", package = "zuarchive"))
archive_read(z, "hello.txt")
#> [1] 68 65 6c 6c 6f
archive_read(z, "hello.txt", as = "text")
#> [1] "hello"