Archiving
The functions for working with zip and tar.gz archives are described here.

Functions

ArchiveName(finfo fi, str root) str

The ArchiveName function concatenates the Name and Dir fields in a variable of finfo type and returns the file path for the archive relative to the root path root.

CloseTarGz(handle h)

The CloseTarGz function finishes creating the .tar.gz archive. The h parameter is the identifier that was returned by the CreateTarGz function.

CloseZip(handle h)

The CloseZip function finishes creating the .zip archive. The h parameter is the identifier that was returned by the CreateZip function.

CreateTarGz(str name) handle

The CreateTarGz function starts creating a .tar.gz archive with the specified name. You can add files to this archive with the CompressFile function. The function returns an identifier, which you will need to close with the CloseTarGz function.

CreateZip(str name) handle

The CreateZip function starts creating a .tar.gz archive with the specified name. You can add files to this archive with the CompressFile function. The function returns an identifier, which you will need to close with the CloseZip function.

CompressFile(handle h, str fname, str packname)

The CompressFile function adds the specified fname file to the created archive. The packname parameter contains the relative path and file name to be saved in the archive. Use / symbol as a separator. The archive must be previously created using the CreateZip or CreateTarGz functions.
1
handle zip = CreateZip(`my.zip`)
2
CompressFile(zip, `../data/my.txt`, `my.txt`)
3
CompressFile(zip, `/home/user/folder/copy.txt`, `folder/copy.txt`)
4
CloseZip(zip)
Copied!

ReadTarGz(str name) arr.finfo

The ReadTarGz function returns the list of files in the specified tar.gz archive. The Name field contains the file name together with the relative path.
1
arr.finfo list = ReadTarGz(`my.tar.gz`)
2
for fi in list : Println( "\{fi.Name} \{fi.Size}")
Copied!

ReadZip(str name) arr.finfo

The ReadZip function returns the list of files in the specified .zip archive. The Name field contains the file name together with the relative path.

TarGz(str name, str path)

The TarGz function packs the file or the contents of the path directory into a .tar.gz archive named name.
1
TarGz("/home/user/out/my.tar.gz", `/home/user/docs`)
Copied!

UnpackTarGz(str name, str path)

The UnpackTarGz function unpacks a .tar.gz archive named name into the path directory.
1
UnpackTarGz("/home/user/out/my.tar.gz", `/home/user/olddocs`)
Copied!

UnpackTarGz(str name, str path, arr pattern, arr ignore)

The UnpackTarGz function selectively unpacks a .tar.gz archive named name into the path directory. The pattern array contains file patterns to be unpacked. The ignore array contains file patterns to skip. The pattern and ignore parameters can be empty arrays. If the pattern begins and ends with /, then it is treated as a regular expression.
1
arr empty
2
arr doc = {`*.docx`, `/.txt$/`}
3
UnpackTarGz("/home/user/out/my.tar.gz", `/home/user/tmp`, doc, empty )
Copied!

UnpackZip(str name, str path)

The UnpackZip function unpacks a .zip archive named name into the path directory.
1
UnpackZip("/home/user/out/my.zip", `/home/user/olddocs`)
Copied!

UnpackZip(str name, str path, arr pattern, arr ignore)

The UnpackZip function selectively unpacks a .tar.gz archive named name into the path directory. The pattern array contains file patterns to be unpacked. The ignore array contains file patterns to skip. The pattern and ignore parameters can be empty arrays. If the pattern begins and ends with /, then it is treated as a regular expression.
1
arr empty
2
arr skip = {`/temp.pdf/`, `/.txt$/`}
3
UnpackZip("/home/user/out/my.tar.gz", `/home/user/tmp`, empty, skip )
Copied!

Zip(str name, str path)

The Zip function packs the file or the contents of the path directory into a .zip archive named name.
1
Zip("/home/user/out/mydoc.zip", `/home/user/docs/important.docx`)
Copied!
Last modified 9mo ago