zip - Compression and archives
The zip module compresses and extracts files and supports password-protected archives (zip4j).
See also
Table of contents
Interfaces
Type aliases
Functions
Type aliases
ZipFileAttribute
ZipFileAttribute: "all" | "archive" | "dateTime" | "hidden" | "system" | "readOnly"
Entry attribute flags when reading or writing zip metadata:
all: all attributesarchive: archive bitdateTime: timestamphidden: hidden flagreadOnly: read-only flagsystem: system file flag
See also
Functions
open
open(file: string): ZipFile`
Opens a zip archive for further operations.
Parameters
file: Path to the.zipfile.
Returns
unzip
unzip(zipFile: string, dest: string, options?: UnzipOptions ): Promise<void>
Extracts an archive. If dest does not exist, it is created and files go inside it. If dest already exists, a subfolder named after the zip file is created under dest and contents are extracted there.
Example
"nodejs";
const { unzip, zipDir } = require('zip');
async function main() {
const zipFilePath = './dest.zip';
await zipDir('./dir', zipFilePath, { password: 'Auto.js Pro' });
await unzip(zipFilePath, './dest', { password: 'Auto.js Pro' });
}
main();Parameters
zipFile: Path to the archive to extract.dest: Output directory.options: OptionalUnzipOptions.
Returns
Promise<void>
zipDir
zipDir(dir: string, dest: string, options?: ZipOptions ): Promise< ZipFile >
Zips a folder recursively into dest.
Example
const { zipDir } = require('zip');
zipDir('./dir', './dest.zip')
.then(zipFile => console.log(zipFile));Parameters
dir: Folder to compress (includes subfolders).dest: Output.zippath.options: OptionalZipOptions.
Returns
Promise< ZipFile >
zipFile
zipFile(file: string, dest: string, options?: ZipOptions ): Promise< ZipFile >
Zips a single file to dest.
Example
const { zipFile } = require('zip');
zipFile('./file.txt', './dest.zip')
.then(zipFile => console.log(zipFile));Parameters
file: File to compress.dest: Output.zippath.options: OptionalZipOptions.
Returns
Promise< ZipFile >
zipFiles
zipFiles(fileList: string[], dest: string, options?: ZipOptions ): Promise< ZipFile >
Zips many files into dest. fileList must not contain directories—only files.
Example
const { zipFiles } = require('zip');
zipFiles(['./file1.txt', './file2.txt'], './dest.zip')
.then(zipFile => console.log(zipFile));Parameters
fileList: Paths of files to include.dest: Output.zippath.options: OptionalZipOptions.
Returns
Promise< ZipFile >
