Skip to content

Creates and extracts `.tar` archives, optionally gzip-compressed, in the project workspace. The archive is compressed with gzip when its name ends with `.tgz`, `.tar.gz` or `.gz` (checked ignoring case), for both creating and extracting; any other name gives a plain tar. Archiving a directory stores it under its own name, and extracting never writes outside the destination directory. Symbolic and hard links are kept as links; other special entries (devices, FIFOs) are skipped.

Functions

  • create self Archives a file or a whole directory into a tar file.
  • extract self Extracts a tar archive (gzip-compressed when the name ends in `.tgz`, `.tar.gz` or `.gz`) into a directory, creating the directory when needed.
Tar.create(source: string, destination: string)→self

Archives a file or a whole directory into a tar file. A file is stored under its file name; a directory is stored with its own name as the top folder. 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. Use a name ending in `.tar.gz` or `.tgz` for a compressed archive. Throws `Failed to create tar archive` when the source does not exist or the archive cannot be written.

Parameters

source string
File or directory to archive, relative to the workspace
destination string
Archive to create, relative to the workspace; `.tar.gz` or `.tgz` compresses

Returns

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

Example runs in CI

Fl.write("hello.txt", "hello")
Tar.create("hello.txt", "hello.tar")
Tar.extract("hello.tar", "untarred")
print(Fl.exists("untarred/hello.txt"))
Tar.extract(archive: string, destination: string)→self

Extracts a tar archive (gzip-compressed when the name ends in `.tgz`, `.tar.gz` or `.gz`) 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, or a link pointing outside it, aborts the extraction. Throws `Failed to extract tar archive` when the archive is missing or damaged. A file that is not a tar archive but has a name that does not end in `.gz` may be accepted and extract nothing.

Parameters

archive string
Archive 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.