User's Manual

160 Chapter 3
Zip Object
The Zip object is used to create and add files to a new zip archive.
Zip Profile Object Methods
The Zip Object implements the following methods:
Zip(), Constructor
addFile()
save()
NOTE: For all paths in the Zip Object that do not specify a file system the default is the write file
system. See “File Systems” on page 14 for more information.
Zip()
Constructor for Zip object.
Parameters
This function takes no parameters.
addFile()
Adds a file to the zip archive. Note that the file is not actually read until the save() method
is called.
Parameters
filePath - specifies the VFS path of file to add to archive.
archivePath - specifies a full path of file as stored in archive.
save()
Creates a new zip archive and compresses all the files specified by calls to addFile().
Parameters
archiveName - specifies a path to new archive file.
Example
var myZip = new Zip();
myZip.addFile("images/image1.jpg", "image1.jpg");
myZip.addFile("images/image2.jpg", "image2.jpg");
myZip.save("zip/files.zip");
The Zip object can also be used as a response object. For example, the following code
creates a zip archive as a cached response:
var myZip = new Zip();
myZip.addFile("images/image1.jpg", "image1.jpg");
myZip.addFile("images/image2.jpg", "image2.jpg");
resp.setObject(myZip);