zip_append()
appends compressed files to an existing 'zip' file.
Relative paths
zip()
and zip_append()
can run in two different modes: mirror
mode and cherry picking mode. They handle the specified files
differently.
Mirror mode
Mirror mode is for creating the zip archive of a directory structure,
exactly as it is on the disk. The current working directory will
be the root of the archive, and the paths will be fully kept.
zip changes the current directory to root
before creating the
archive.
E.g. consider the following directory structure:
.
|-- foo
| |-- bar
| | |-- file1
| | `-- file2
| `-- bar2
`-- foo2
`-- file3
Assuming the current working directory is foo
, the following zip
entries are created by zip
:
setwd("foo")
zip::zip("../test.zip", c("bar/file1", "bar2", "../foo2"))
#> Warning in warn_for_dotdot(data$key): Some paths reference parent directory,
#> creating non-portable zip file
zip_list("../test.zip")[, "filename", drop = FALSE]
#> filename
#> 1 bar/file1
#> 2 bar2/
#> 3 ../foo2/
#> 4 ../foo2/file3
Note that zip refuses to store files with absolute paths, and chops
off the leading /
character from these file names. This is because
only relative paths are allowed in zip files.
Cherry picking mode
In cherry picking mode, the selected files and directories
will be at the root of the archive. This mode is handy if you
want to select a subset of files and directories, possibly from
different paths and put all of the in the archive, at the top
level.
Here is an example with the same directory structure as above:
zip::zip(
"../test2.zip",
c("bar/file1", "bar2", "../foo2"),
mode = "cherry-pick"
)
zip_list("../test2.zip")[, "filename", drop = FALSE]
#> filename
#> 1 file1
#> 2 bar2/
#> 3 foo2/
#> 4 foo2/file3
From zip version 2.3.0, "."
has a special meaning in the files
argument: it will include the files (and possibly directories) within
the current working directory, but not the working directory itself.
Note that this only applies to cherry picking mode.
Permissions:
zip()
(and zip_append()
, etc.) add the permissions of
the archived files and directories to the ZIP archive, on Unix systems.
Most zip and unzip implementations support these, so they will be
recovered after extracting the archive.
Note, however that the owner and group (uid and gid) are currently
omitted, even on Unix.
zipr()
and zipr_append()
These function exist for historical reasons. They are identical
to zip()
and zipr_append()
with a different default for the
mode
argument.