Socket
Socket
Sign inDemoInstall

@types/yauzl

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/yauzl

TypeScript definitions for yauzl


Version published
Weekly downloads
10M
decreased by-1.47%
Maintainers
1
Weekly downloads
 
Created

What is @types/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.

What are @types/yauzl's main functionalities?

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));
    });
  }
});

Other packages similar to @types/yauzl

FAQs

Package last updated on 02 Jul 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc