Gathering detailed insights and metrics for zip-lib
Gathering detailed insights and metrics for zip-lib
npm install zip-lib
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.1
Supply Chain
99.1
Quality
77.5
Maintenance
100
Vulnerability
100
License
TypeScript (96.54%)
JavaScript (3.46%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
4,188,479
Last Day
19,634
Last Week
88,788
Last Month
409,239
Last Year
2,581,945
MIT License
34 Stars
127 Commits
4 Forks
2 Watchers
2 Branches
1 Contributors
Updated on Feb 08, 2025
Minified
Minified + Gzipped
Latest Version
1.0.5
Package Id
zip-lib@1.0.5
Unpacked Size
49.43 kB
Size
11.42 kB
File Count
13
NPM Version
10.9.0
Node Version
20.12.1
Published on
Nov 07, 2024
Cumulative downloads
Total Downloads
Last Day
7.3%
19,634
Compared to previous day
Last Week
-8%
88,788
Compared to previous week
Last Month
-2%
409,239
Compared to previous month
Last Year
215.3%
2,581,945
Compared to previous year
7
zip and unzip library for node.
npm install zip-lib
You can use zip-lib to compress files or folders.
1const zl = require("zip-lib"); 2 3zl.archiveFile("path/to/file.txt", "path/to/target.zip").then(function () { 4 console.log("done"); 5}, function (err) { 6 console.log(err); 7});
1const zl = require("zip-lib"); 2 3zl.archiveFolder("path/to/folder", "path/to/target.zip").then(function () { 4 console.log("done"); 5}, function (err) { 6 console.log(err); 7});
1const zl = require("zip-lib"); 2 3zl.extract("path/to/target.zip", "path/to/target").then(function () { 4 console.log("done"); 5}, function (err) { 6 console.log(err); 7});
1const zl = require("zip-lib"); 2 3zl.archiveFolder("path/to/folder", "path/to/target.zip", { compressionLevel: 9 }).then(function () { 4 console.log("done"); 5}, function (err) { 6 console.log(err); 7});
1const zl = require("zip-lib"); 2 3const zip = new zl.Zip(); 4// Adds a file from the file system 5zip.addFile("path/to/file.txt"); 6// Adds a folder from the file system, putting its contents at the root of archive 7zip.addFolder("path/to/folder"); 8// Generate zip file. 9zip.archive("path/to/target.zip").then(function () { 10 console.log("done"); 11}, function (err) { 12 console.log(err); 13});
The path/to/folder
directory is as follows:
path/to/folder
.
├── dir1
│ ├── file.ext
├── dir2
└── file_in_root.ext
And the generated path/to/target.zip
archive file directory will be as follows:
path/to/target.zip
.
├── file.txt
├── dir1
│ ├── file.ext
├── dir2
└── file_in_root.ext
1const zl = require("zip-lib"); 2 3const zip = new zl.Zip(); 4// Adds a file from the file system 5zip.addFile("path/to/file.txt", "renamedFile.txt"); 6zip.addFile("path/to/file2.txt", "folder/file.txt"); 7// Adds a folder from the file system, and naming it `new folder` within the archive 8zip.addFolder("path/to/folder", "new folder"); 9// Generate zip file. 10zip.archive("path/to/target.zip").then(function () { 11 console.log("done"); 12}, function (err) { 13 console.log(err); 14});
The path/to/folder
directory is as follows:
path/to/folder
.
├── dir1
│ ├── file.ext
├── dir2
└── file_in_root.ext
And the generated path/to/target.zip
archive file directory will be as follows:
path/to/target.zip
.
├── renamedFile.txt
├── folder
│ ├── file.txt
│── new folder
├── dir1
│ ├── file.ext
├── dir2
└── file_in_root.ext
Using onEntry
callback we can know the current progress of extracting and control the extraction operation. See IExtractOptions.
1const zl = require("zip-lib"); 2 3const unzip = new zl.Unzip({ 4 // Called before an item is extracted. 5 onEntry: function (event) { 6 console.log(event.entryCount, event.entryName); 7 } 8}) 9unzip.extract("path/to/target.zip", "path/to/target").then(function () { 10 console.log("done"); 11}, function (err) { 12 console.log(err); 13});
The following code shows how to exclude the __MACOSX
folder in the zip file when extracting. See IExtractOptions.
1const zl = require("zip-lib"); 2 3const unzip = new zl.Unzip({ 4 // Called before an item is extracted. 5 onEntry: function (event) { 6 if (/^__MACOSX\//.test(event.entryName)) { 7 // entry name starts with __MACOSX/ 8 event.preventDefault(); 9 } 10 } 11}) 12unzip.extract("path/to/target.zip", "path/to/target").then(function () { 13 console.log("done"); 14}, function (err) { 15 console.log(err); 16});
If the cancel
method is called after the archive is complete, nothing will happen.
1const zl = require("zip-lib"); 2 3const zip = new zl.Zip(); 4zip.addFile("path/to/file.txt"); 5zip.archive("path/to/target.zip").then(function () { 6 console.log("done"); 7}, function (err) { 8 if (err.name === "Canceled") { 9 console.log("cancel"); 10 } else { 11 console.log(err); 12 } 13}); 14 15// Cancel zip 16zip.cancel();
If the cancel
method is called after the extract is complete, nothing will happen.
1const zl = require("zip-lib"); 2 3const unzip = new zl.Unzip(); 4unzip.extract("path/to/target.zip", "path/to/target").then(function () { 5 console.log("done"); 6}, function (err) { 7 if (err.name === "Canceled") { 8 console.log("cancel"); 9 } else { 10 console.log(err); 11 } 12}); 13 14// cancel 15unzip.cancel();
archiveFile(file, zipFile, [options])
Compress a single file to zip.
file
: StringzipFile
: Stringoptions?
: IZipOptions (optional)Returns: Promise<viod>
archiveFolder(folder, zipFile, [options])
Compress all the contents of the specified folder to zip.
folder
: StringzipFile
: Stringoptions?
: IZipOptions (optional)Returns: Promise<void>
extract(zipFile, targetFolder, [options])
Extract the zip file to the specified location.
zipFile
: StringtargetFolder
: Stringoptions?
: IExtractOptions (optional)Returns: Promise<void>
Compress files or folders to a zip file.
Constructor: new Zip([options])
options?
: IZipOptionsMethod: addFile(file, [metadataPath])
Adds a file from the file system at realPath into the zipfile as metadataPath.
file
: StringmetadataPath?
: String (optional) - Typically metadataPath would be calculated as path.relative(root, realPath). A valid metadataPath must not start with /
or /[A-Za-z]:\//
, and must not contain ..
.Returns: void
Method: addFolder(folder, [metadataPath])
Adds a folder from the file system at realPath into the zipfile as metadataPath.
folder
: StringmetadataPath?
: String (optional) - Typically metadataPath would be calculated as path.relative(root, realPath). A valid metadataPath must not start with /
or /[A-Za-z]:\//
, and must not contain ..
.Returns: void
Method: archive(zipFile)
Generate zip file.
zipFile
: StringReturns: Promise<viod>
Method: cancel()
Cancel compression. If the cancel
method is called after the archive is complete, nothing will happen.
Returns: void
Extract the zip file.
Constructor: new Unzip([options])
options?
: IZipOptions (optional)Method: extract(zipFile, targetFolder)
Extract the zip file to the specified location.
zipFile
: StringtargetFolder
: StringReturns: Promise<void>
Method: cancel()
If the cancel
method is called after the extract is complete, nothing will happen.
Returns: void
Object
followSymlinks?
: Boolean (optional) - Indicates how to handle when the given path is a symbolic link. The default value is false
.true
: add the target of the symbolic link to the zip.false
: add symbolic link itself to the zip.compressionLevel?
: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 - Sets the compression level. The default value is 6
.0
: the file data will be stored.1-9
: the file data will be deflated.Object
overwrite?
: String (optional) - If it is true, the target directory will be deleted before extract. The default value is false
.
symlinkAsFileOnWindows?
: Boolean (optional) - Extract symbolic links as files on Windows. This value is only available on Windows and ignored on other platforms. The default value is true
.
If true
, the symlink in the zip will be extracted as a normal file on Windows.
If false
, the symlink in the zip will be extracted as a symlink correctly on Windows, but an EPERM
error will be thrown under non-administrators.
⚠WARNING: On Windows, the default security policy allows only administrators to create symbolic links. If you set
symlinkAsFileOnWindows
tofalse
and the zip contains symlink, be sure to run the code under the administrator, otherwise anEPERM
error will be thrown.
onEntry?
: Function (optional) - Called before an item is extracted.
Arguments:
event
: Object - Represents an event that an entry is about to be extracted.
entryName
: String (readonly) - Entry name.entryCount
: Number (readonly) - Total number of entries.preventDefault()
: Function - Prevent extracting current entry. This method can be used to prevent extraction of the current item. By calling this method we can control which items can be extracted.Licensed under the MIT license.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
6 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More