Security News
OpenJS: “XZ Utils Cyberattack Likely Not an Isolated Incident”
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
@types/yauzl
Advanced tools
Weekly downloads
Package description
The @types/yauzl package provides TypeScript type definitions for the yauzl package, which is a library for unzipping files. These type definitions allow TypeScript developers to use yauzl in their projects with the benefits of TypeScript's static type checking. The main functionalities of yauzl, and thus @types/yauzl, revolve around reading and extracting zip files.
Opening a zip file
This code demonstrates how to open a zip file using yauzl. It uses the `open` method, specifying the path to the zip file and options, then reads the first entry in the zip file.
import * as yauzl from 'yauzl';
yauzl.open('path/to/file.zip', {lazyEntries: true}, (err, zipfile) => {
if (err) throw err;
zipfile.readEntry();
});
Reading entries from a zip file
This code snippet is used within the context of an open zipfile object. It listens for 'entry' events, which occur each time a new entry in the zip file is ready to be read, logging the file name of each entry and then reading the next entry.
zipfile.on('entry', (entry) => {
console.log(`Entry: ${entry.fileName}`);
zipfile.readEntry();
});
Extracting file entries
This example shows how to extract files from a zip archive. It checks if the entry is a file (not a directory) and then creates a read stream for that entry. The stream is piped to a write stream that writes the file to a specified output path.
zipfile.on('entry', (entry) => {
if (/\/.test(entry.fileName)) {
zipfile.readEntry();
} else {
zipfile.openReadStream(entry, (err, readStream) => {
if (err) throw err;
readStream.on('end', () => {
zipfile.readEntry();
});
readStream.pipe(fs.createWriteStream('output/path/' + entry.fileName));
});
}
});
adm-zip is a JavaScript implementation for zip data compression for NodeJS. It provides functionalities similar to yauzl, such as reading and extracting zip files, but also includes the ability to create zip files. Compared to yauzl, adm-zip offers a broader feature set but might not be as efficient for large zip files.
jszip is another popular library for working with zip files in JavaScript. It supports both Node.js and browser environments, making it more versatile than yauzl. jszip allows reading, creating, and modifying zip files. While it provides a more comprehensive API for handling zip files, it might be overkill for simple unzipping tasks.
unzipper is a fork of the decompress-zip package and provides an easy way to extract zip files. It is designed to handle both small and large zip files efficiently. Compared to yauzl, unzipper offers a simpler API and automatic detection of the zip file encoding.
Readme
npm install --save @types/yauzl
This package contains type definitions for yauzl (https://github.com/thejoshwolfe/yauzl).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/yauzl.
These definitions were written by Florian Keller.
FAQs
TypeScript definitions for yauzl
The npm package @types/yauzl receives a total of 8,626,204 weekly downloads. As such, @types/yauzl popularity was classified as popular.
We found that @types/yauzl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
Company News
Come meet the Socket team at BSidesSF and RSA! We're sponsoring several fun networking events and we would love to see you there.
Security News
OSI is starting a conversation aimed at removing the excuse of the SaaS loophole for companies navigating licensing and the complexities of doing business with open source.