zip_extract: Uncompress 'zip' Archives

Description Usage Arguments Value Permissions Examples

View source: R/extract.R

Description

zip_extract() always restores modification times of the extracted files and directories.

Usage

1
2
3
4
5
6
7
zip_extract(
  zipfile,
  files = NULL,
  overwrite = TRUE,
  junk_paths = FALSE,
  exdir = "."
)

Arguments

zipfile

Path to the zip file to uncompress.

files

Character vector of files to extract from the archive. Files within directories can be specified, but they must use a forward slash as path separator, as this is what zip files use internally. If NULL (default), all files will be extracted.

overwrite

Whether to overwrite existing files. If FALSE and a file already exists, then an error is thrown.

junk_paths

Whether to ignore all directory paths when creating files. If TRUE, all files will be extracted to the top level of exdir.

exdir

Directory to uncompress the archive to. If it does not exist, it will be created.

Value

An fs::fs_path() character vecttor of extracted files, invisibly.

This is like the "internal" method of utils::unzip() and unlike zip::unzip() (See r-lib/zip#35). The zip_info() C internal is called separately to get file names, which are not yet returned from the C internal used for extraction.

Permissions

If the zip archive stores permissions and was created on Unix, the permissions will be restored.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
library(fs)
dir_create("mydir")
cat("first file",  file = path("mydir", "file1"))
cat("second file", file = path("mydir", "file2"))

z <- file_temp(ext = "zip")
zip_create("mydir", z)

## List contents
zip_info(z)

## Extract
tmp <- path_temp()
out <- zip_extract(z, exdir = tmp)
length(out)

kiernann/zippr documentation built on Feb. 17, 2021, 5:59 p.m.