yauzl
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
buffer-crc32 | 0.2.13 | 4.07 kB | MIT | prod | |
fd-slicer | 1.1.0 | 7.34 kB | MIT | prod |
Yauzl is an efficient unzip library designed for Node.js. The library follows the principles of not blocking the JavaScript thread, not scanning for local file headers, and ensuring low memory usage by not buffering entire files in RAM at once. It focuses on providing asynchronous APIs for careful, foolproof, and performant handling of ZIP files. Yauzl also emphasizes the importance of error handling, catching unsafe file names, and providing resilience against malformed zip files to ensure that client applications do not run into issues.
In order to use yauzl, first, ensure it has been installed by running npm install yauzl on your command line. Once installed, include yauzl in your JavaScript file by using the require statement.
var yauzl = require("yauzl");
To open, read, and perform operations on a zip file, use the open method. The code snippet below exhibits how to open a zip file and read its contents:
yauzl.open("path/to/file.zip", {lazyEntries: true}, function(err, zipfile) {
if (err) throw err;
zipfile.readEntry();
zipfile.on("entry", function(entry) {
if (/\/$/.test(entry.fileName)) {
zipfile.readEntry();
} else {
zipfile.openReadStream(entry, function(err, readStream) {
if (err) throw err;
readStream.on("end", function() {
zipfile.readEntry();
});
readStream.pipe(somewhere);
});
}
});
});
In the example, we open a file, read directory entries one by one, open a readable stream for each file entry, then pipe the readStream to a destination.
The documentation for yauzl is extensive and is primarily located on its GitHub repository README at https://github.com/thejoshwolfe/yauzl. The documentation effectively covers the usage of yauzl, providing in-depth descriptions of its API interfaces, usage principles, error handling procedures, design details, and the limitations it has with regards to the .zip file format. The README also contains valuable information on how yauzl handles data encoding, RHS timestamp and permission issues that are common when dealing with zip files from different operating systems.