Interface: ZipFile
zip.ZipFile
Handle returned by open. Lets you mutate an archive (add/remove entries), inspect FileHeader metadata, and extract files.
Table of contents
Methods
- addFile
- addFiles
- addFolder
- extractAll
- extractFile
- getFileHeader
- getFileHeaders
- getPath
- isEncrypted
- isValidZipFile
- removeFile
- setPassword
Methods
addFile
addFile(file, options?): Promise<void>
Appends a single file from disk into the open archive.
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 | Absolute or project-relative path on disk. |
options? | ZipOptions | Compression / encryption options. |
Returns
Promise<void>
addFiles
addFiles(fileList, options?): Promise<void>
Batch version of addFile.
Parameters
| Name | Type | Description |
|---|---|---|
fileList | string[] | Paths to include. |
options? | ZipOptions | Optional compression settings. |
Returns
Promise<void>
addFolder
addFolder(folder, options?): Promise<void>
Recursively packs a directory.
Parameters
| Name | Type | Description |
|---|---|---|
folder | string | Folder path on disk. |
options? | ZipOptions | Layout / compression options. |
Returns
Promise<void>
extractAll
extractAll(dest, options?): Promise<void>
Unpacks every entry under dest.
Parameters
| Name | Type | Description |
|---|---|---|
dest | string | Output directory (created if needed). |
options? | UnzipOptions | Password / attribute tweaks. |
Returns
Promise<void>
extractFile
extractFile(file, dest, options?, newFileName?): Promise<void>
Extracts one member. Throws if dest is unusable or the member is missing.
Parameters
| Name | Type | Description |
|---|---|---|
file | string | In-zip entry path. |
dest | string | Output folder or file path. |
options? | UnzipOptions | Decryption / attribute options. |
newFileName? | string | Optional rename after extraction. |
Returns
Promise<void>
getFileHeader
getFileHeader(file): any
Returns a Zip4j FileHeader object (CRC, encryption flags, comment, …).
Parameters
| Name | Type | Description |
|---|---|---|
file | string | Entry name inside the archive. |
Returns
any — see FileHeader.
getFileHeaders
getFileHeaders(): any[]
Lists all headers.
Returns
any[] — array of FileHeader.
getPath
getPath(): string
Filesystem path of the opened .zip.
Returns
string
isEncrypted
isEncrypted(): boolean
Whether the archive uses password encryption.
Returns
boolean
isValidZipFile
isValidZipFile(): boolean
false when the backing path is missing or not a readable zip.
Returns
boolean
removeFile
removeFile(file): Promise<void>
Deletes file from the mutable archive. Throws if the entry does not exist. Split / spanned zip sets cannot be modified—throws per Zip spec.
Parameters
| Name | Type | Description |
|---|---|---|
file | string | Entry to remove. |
Returns
Promise<void>
setPassword
setPassword(password): void
Required before extract* on encrypted archives. Wrong / missing passwords throw (often ZipException).
Parameters
| Name | Type | Description |
|---|---|---|
password | string | Decryption password. |
Returns
void
