Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@types/yauzl
Advanced tools
TypeScript definitions for yauzl
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.
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 4,839,310 weekly downloads. As such, @types/yauzl popularity was classified as popular.
We found that @types/yauzl demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.