Interface: ZipFile


CloudControl Pro 9 Docs / zip / ZipFile

Interface: ZipFile

zip.ZipFile

open返回的对象,用于在压缩包中增删文件、获取文件头信息、解压等。

Table of contents

Methods

Methods

addFile

addFile(file, options?): Promise<void>

Add a file to the ZIP file.

Example

const zip = require('zip);
async function main() {
    const zipFile = await zip.open('test.zip');
    await zipFile.addFile('test.txt');
}
main();

Parameters

Name Type Description
file string Local file path
options? ZipOptions Compress options

Returns

Promise<void>


addFiles

addFiles(fileList, options?): Promise<void>

Add multiple files to the ZIP file.

Parameters

Name Type Description
fileList string[] Array of local file paths
options? ZipOptions Compress options

Returns

Promise<void>


addFolder

addFolder(folder, options?): Promise<void>

Add a folder to the ZIP file.

Parameters

Name Type Description
folder string Folder path
options? ZipOptions Compress options

Returns

Promise<void>


extractAll

extractAll(dest, options?): Promise<void>

Extract all files from the ZIP file to the target path dest.

Parameters

Name Type Description
dest string Extract path
options? UnzipOptions Extract options

Returns

Promise<void>


extractFile

extractFile(file, dest, options?, newFileName?): Promise<void>

Extract a file from the ZIP file. If the target path is invalid, this method will throw an exception.

Parameters

Name Type Description
file string File to extract
dest string Destination path
options? UnzipOptions Extract options
newFileName? string New file name, optional

Returns

Promise<void>


getFileHeader

getFileHeader(file): any

Get the file header information of the specified file in the ZIP file. The file header information includes the checksum, whether the file is encrypted, comments, etc.

Parameters

Name Type Description
file string File path in the ZIP file

Returns

any

FileHeaderopen in new window


getFileHeaders

getFileHeaders(): any[]

Get the file header information of all files in the ZIP file. The file header information includes the checksum, whether the file is encrypted, comments, etc.

Returns

any[]

Array of FileHeaderopen in new window


getPath

getPath(): string

Get the path of the current ZIP file.

Returns

string


isEncrypted

isEncrypted(): boolean

Get whether the current ZIP file is an encrypted ZIP file.

Returns

boolean

Whether the current ZIP file is an encrypted ZIP file.


isValidZipFile

isValidZipFile(): boolean

Get whether the current ZIP file is a valid ZIP file. If the path is not a ZIP file or the file does not exist, return false.

Returns

boolean

Whether the current ZIP file is a valid ZIP file.


removeFile

removeFile(file): Promise<void>

Delete a file from the ZIP file. If the file does not exist, this method will throw an exception.

If the ZIP file is a segmented ZIP file, this method will throw an exception, because the zip specification does not allow updating a segmented ZIP file.

Parameters

Name Type Description
file string File to delete

Returns

Promise<void>


setPassword

setPassword(password): void

If the ZIP file is encrypted, you must use this function to set the correct password to decrypt the encrypted file. If you do not set the password, an exception will be thrown when you try to decrypt the encrypted ZIP file.

Parameters

Name Type Description
password string Password

Returns

void