zip

Since 1.5.0

Contains functions for working with zip archives

Functions

zip(inputPath, outputFile, mapper = def(entryPath) = entryPath) — creates a zip archive with the contents of inputPath and saves to outputFile.
mapper is used to set the name of the final file inside the archive and for filtering. If the mapper returns an empty string, the file will be skipped.
Returns the number of archived files, or -1 if the archive could not be created.

use zip
// Zip all files in directory
zip("/tmp/dir", "/tmp/1.zip")
// Zip .txt files
zip("/tmp/dir", "/tmp/2.zip", def(p) = p.endsWith(".txt") ? p : "")

zipFiles(input, outputFile) — creates a zip archive with the contents of inputPath and saves to outputFile.
If input is a string, then a single file or the contents of a folder is archived.
If input is an array, then the files and folders listed in it are archived.
If input is an associative array, then the files and folders listed in the keys are archived and the names inside the archive will be the values of an array.
Returns the number of archived files, or -1 if the archive could not be created.

use zip
zipFiles("/tmp/dir/file.txt", "/tmp/1.zip")
zipFiles(["/tmp/dir/file.txt", "/tmp/dir/readme.md"], "/tmp/2.zip")
zipFiles({"/tmp/dir/file.txt" : "docs/1.md", "/tmp/dir/readme.md" : "docs/2.md"}, "/tmp/3.zip")

unzip(input, output, mapper = def(entryName) = entryPath) — unpacks a zip archive to output directory.
mapper is used to set the name of the final file and for filtering. If the mapper returns an empty string, the file will be skipped.
Returns the number of unzipped files, or -1 if unzipping the archive was failed.

use zip
// Unzip all files in directory
unzip("/tmp/1.zip", "/tmp/dir")
// Unzip .txt files
unzip("/tmp/2.zip", "/tmp/dir", def(p) = p.endsWith(".txt") ? p : "")

unzipFiles(input, output) — unpacks a output files from zip archive .
If output is a string, then a single file is unzipped.
If output is an array, then the files listed in it are unzipped.
If output is an associative array, the files listed in the keys are unzipped and the values will be file names.
Returns the number of unzipped files, or -1 if unzipping the archive was failed.

use zip
unzipFiles("/tmp/1.zip", "file.txt")
unzipFiles("/tmp/2.zip", ["file.txt", "readme.md"])
unzipFiles("/tmp/3.zip", {"docs/1.md" : "/tmp/dir/file.txt", "docs/2.md" : "/tmp/dir/readme.md"})

listZipEntries(input) — returns an array of zip archive filenames