Skip to content

Creates and extracts `.zip` archives in the project workspace. Archiving a directory stores it under its own name (zipping `data` gives entries `data/...`), and extracting an archive never writes outside the destination directory. Symbolic links are stored as links and not followed. Password-protected archives are not supported.

Functions

  • create self Zips a file or a whole directory.
  • extract self Extracts a zip archive into a directory, creating the directory when needed.
Zip.create(source: string, destination: string)→self

Zips a file or a whole directory. A file is stored under its file name; a directory is stored together with its own name as the top folder, so zipping `data` and extracting the result gives `data/...` again. The archive is replaced if it exists, its missing parent directories are created, and the archive itself is left out when it lies inside the source directory. Throws `Failed to create zip archive` (for example `Source path does not exist`). No partial archive is left at the destination after a failure.

Parameters

source string
File or directory to zip, relative to the workspace
destination string
Zip file to create, relative to the workspace

Returns

self chainable The library itself, so calls can be chained.

Example runs in CI

Fl.write("hello.txt", "hello")
Zip.create("hello.txt", "hello.zip")
Zip.extract("hello.zip", "unzipped")
print(Fl.exists("unzipped/hello.txt"))
Zip.extract(archive: string, destination: string)→self

Extracts a zip archive into a directory, creating the directory when needed. Existing files with the same name are overwritten. An entry whose path would end up outside the destination (for example `../x`), or a symbolic link pointing outside it, aborts the extraction. Throws `Failed to extract zip archive` when the archive is missing or not a zip file; entries extracted before an error stay on disk.

Parameters

archive string
Zip file to extract, relative to the workspace
destination string
Directory to extract into, relative to the workspace

Returns

self chainable The library itself, so calls can be chained.