CreateNewArchive (open)

Create a new archive file object

Syntax

LOADLIB "wh::filetypes/archiving.whlib";

OBJECT FUNCTION CreateNewArchive(STRING type, RECORD options)

Parameters

STRING type

Type of archive. Possible options: 'zip', 'tar.gz'/'targz'/'tgz'.

RECORD options

Options

compressionlevel

Compression level for new files, 1-9. Defaults to 6.

Return value

OBJECT

Archive object

Description

This function creates an empty new archive file object

Examples

// Creating an archive, adding files/folders and writing the
// archive to disk
OBJECT archive1 := CreateNewArchive("zip");

// Get files from the database
RECORD file1 := SELECT name, data, modificationdate FROM system.fs_objects
                WHERE ID =13;
RECORD file2 := SELECT name, data, modificationdate FROM system.fs_objects
                WHERE ID =21;

//Add File1 to a folder in the root of the archive
archive->AddFile(file1.name, File1.data, file1.modificationdate);

//Add File2 to a folder 'temp/tmp' in the root of the archive
archive->AddFile("/temp/tmp/" || file2.name, file2.data, file2.modificationdate);

//Add folder '/temp/tmp/backup/' to archive, with modtime in 1999.
archive->AddFolder("/temp/tmp/backup/", MakeDate(1999, 10, 11));

//Finish writing to the archive
BLOB ArchiveBlob := archive1->MakeBlob();

//Create a disk file from the archive blob
StoreDiskFile("/tmp/myarchive.zip", archiveblob);