Socket
Socket
Sign inDemoInstall

extract-zip

Package Overview
Dependencies
14
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-zip

unzip a zip file into a directory using 100% javascript


Version published
Maintainers
2
Weekly downloads
13,358,722
decreased by-11.91%

Weekly downloads

Package description

What is extract-zip?

The extract-zip npm package is a cross-platform library that allows users to extract the contents of ZIP archives. It provides a simple API to unzip files and directories, supporting both callback and promise-based workflows.

What are extract-zip's main functionalities?

Extract entire ZIP archive

This feature allows users to extract all contents of a ZIP file to a specified directory. The code sample demonstrates how to use the package with async/await to extract an archive.

const extract = require('extract-zip');

async function extractZip(zipPath, outputPath) {
  try {
    await extract(zipPath, { dir: outputPath });
    console.log('Extraction complete');
  } catch (err) {
    console.error('An error occurred:', err);
  }
}

extractZip('path/to/archive.zip', 'path/to/extract');

Extract ZIP archive with options

This feature allows users to extract a ZIP file with additional options, such as providing a callback for each entry. The code sample shows how to skip a specific file during extraction.

const extract = require('extract-zip');

extract('path/to/archive.zip', { dir: 'path/to/extract', onEntry: (entry, zipfile) => {
  if (entry.fileName === 'unwanted_file.txt') {
    zipfile.readEntry();
  }
}}, function (err) {
  if (err) {
    console.error('Error extracting zip', err);
    return;
  }
  console.log('Extraction part of zip complete');
});

Other packages similar to extract-zip

Readme

Source

extract-zip

Unzip written in pure JavaScript. Extracts a zip into a directory. Available as a library or a command line program.

Uses the yauzl ZIP parser.

NPM Uses JS Standard Style Build Status

Installation

Make sure you have Node 10 or greater installed.

Get the library:

npm install extract-zip --save

Install the command line program:

npm install extract-zip -g

JS API

const extract = require('extract-zip')

async function main () {
  try {
    await extract(source, { dir: target })
    console.log('Extraction complete')
  } catch (err) {
    // handle any errors
  }
}

Options

  • dir (required) - the path to the directory where the extracted files are written
  • defaultDirMode - integer - Directory Mode (permissions), defaults to 0o755
  • defaultFileMode - integer - File Mode (permissions), defaults to 0o644
  • onEntry - function - if present, will be called with (entry, zipfile), entry is every entry from the zip file forwarded from the entry event from yauzl. zipfile is the yauzl instance

Default modes are only used if no permissions are set in the zip file.

CLI Usage

extract-zip foo.zip <targetDirectory>

If not specified, targetDirectory will default to process.cwd().

Keywords

FAQs

Last updated on 10 Jun 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc