zip
CloudControl Pro 9 Docs / zip
zip
The Zip module provides APIs to handle file compression and decompression, and supports encryption.
See
Table of contents
Interfaces
Type Aliases
Functions
Type Aliases
ZipFileAttribute
Ƭ ZipFileAttribute: "all" | "archive" | "dateTime" | "hidden" | "system" | "readOnly"
See
Functions
open
▸ open(file): ZipFile
Open a zip file and return a ZipFile object. You can perform more operations on the returned object.
Parameters
| Name | Type | Description | 
|---|---|---|
| file | string | The path of the zip file. | 
Returns
unzip
▸ unzip(zipFile, dest, options?): Promise<void>
Unzip a zip file. If dest directory does not exist, create it and unzip the content to it; if dest directory exists, create a folder with the same name as zipFile in dest and unzip the content to it.
Example
"nodejs";
const { unzip, zipDir } = require('zip');
async function main() {
    // create a zip file with password
    const zipFilePath = './dest.zip';
    await zipDir('./dir', zipFilePath, { password: 'CloudControl Pro' });
    // unzip the zip file
    await unzip(zipFilePath, './dest', { password: 'CloudControl Pro' });
}
main();
Parameters
| Name | Type | 
|---|---|
| zipFile | string | 
| dest | string | 
| options? | UnzipOptions | 
Returns
Promise<void>
zipDir
▸ zipDir(dir, dest, options?): Promise<ZipFile>
Compress all files and folders under dir to dest.
Example
const { zipDir } = require('zip');
zipDir('./dir', './dest.zip')
 .then(zipFile => console.log(zipFile));
Parameters
| Name | Type | Description | 
|---|---|---|
| dir | string | The path of the folder to be compressed. | 
| dest | string | The path of the target zip file. | 
| options? | ZipOptions | Optional parameters. | 
Returns
Promise<ZipFile>
zipFile
▸ zipFile(file, dest, options?): Promise<ZipFile>
Compress a single file file to dest.
Example
const { zipFile } = require('zip');
zipFile('./file.txt', './dest.zip')
 .then(zipFile => console.log(zipFile));
Parameters
| Name | Type | Description | 
|---|---|---|
| file | string | The path of the file to be compressed. | 
| dest | string | The path of the target zip file. | 
| options? | ZipOptions | Optional parameters. | 
Returns
Promise<ZipFile>
zipFiles
▸ zipFiles(fileList, dest, options?): Promise<ZipFile>
Compress multiple files fileList to dest. fileList cannot contain folders.
Example
const { zipFiles } = require('zip');
zipFiles(['./file1.txt', './file2.txt'], './dest.zip')
 .then(zipFile => console.log(zipFile));
Parameters
| Name | Type | Description | 
|---|---|---|
| fileList | string[] | The array of paths of the files to be compressed. | 
| dest | string | The path of the target zip file. | 
| options? | ZipOptions | Optional parameters. | 
Returns
Promise<ZipFile>
