Zip

Manages a zip archive.

Constructor

new Zip()

Methods

addDir(dirPath, zipPathopt) → (non-null) {Promise.<?>}

Recursively adds a directory and all of its contents to this archive.

Parameters:
NameTypeAttributesDescription
dirPathstring

path to the directory to add.

zipPathstring<optional>

path to the folder in the archive to add the directory contents to. Defaults to the root folder.

Returns:

returns a promise that will resolve when the operation is complete.

Type: 
Promise.<?>

addFile(filePath, zipPathopt) → (non-null) {Promise.<?>}

Adds a file to this zip.

Parameters:
NameTypeAttributesDescription
filePathstring

path to the file to add.

zipPathstring<optional>

path to the file in the zip archive, defaults to the basename of filePath.

Returns:

a promise that will resolve when added.

Type: 
Promise.<?>

getFile(path) → (non-null) {Promise.<!Buffer>}

Returns the contents of the file in this zip archive with the given path. The returned promise will be rejected with an InvalidArgumentError if either path does not exist within the archive, or if path refers to a directory.

Parameters:
NameTypeDescription
pathstring

the path to the file whose contents to return.

Returns:

a promise that will be resolved with the file's contents as a buffer.

Type: 
Promise.<!Buffer>

has(path) → {boolean}

Parameters:
NameTypeDescription
pathstring

File path to test for within the archive.

Returns:

Whether this zip archive contains an entry with the given path.

Type: 
boolean

toBuffer(compression) → (non-null) {Promise.<!Buffer>}

Returns the compressed data for this archive in a buffer. This method will not wait for any outstanding add operations before encoding the archive.

Parameters:
NameTypeDefaultDescription
compressionstringSTORE

The desired compression. Must be STORE (the default) or DEFLATE.

Returns:

a promise that will resolve with this archive as a buffer.

Type: 
Promise.<!Buffer>