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.

    handle zip = CreateZip(`my.zip`)
    CompressFile(zip, `../data/my.txt`, `my.txt`)
    CompressFile(zip, `/home/user/folder/copy.txt`, `folder/copy.txt`)
    CloseZip(zip)

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.

   arr.finfo list = ReadTarGz(`my.tar.gz`)
   for fi in list : Println( "\{fi.Name} \{fi.Size}")

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.

   TarGz("/home/user/out/my.tar.gz", `/home/user/docs`)

UnpackTarGz(str name, str path)

The UnpackTarGz function unpacks a .tar.gz archive named name into the path directory.

   UnpackTarGz("/home/user/out/my.tar.gz", `/home/user/olddocs`)

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.

   arr empty
   arr doc = {`*.docx`, `/.txt$/`}
   UnpackTarGz("/home/user/out/my.tar.gz", `/home/user/tmp`, doc, empty )

UnpackZip(str name, str path)

The UnpackZip function unpacks a .zip archive named name into the path directory.

   UnpackZip("/home/user/out/my.zip", `/home/user/olddocs`)

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.

   arr empty
   arr skip = {`/temp.pdf/`, `/.txt$/`}
   UnpackZip("/home/user/out/my.tar.gz", `/home/user/tmp`, empty, skip )

Zip(str name, str path)

The Zip function packs the file or the contents of the path directory into a .zip archive named name.

   Zip("/home/user/out/mydoc.zip", `/home/user/docs/important.docx`)

Last updated