Socket
Socket
Sign inDemoInstall

decompress

Package Overview
Dependencies
33
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    decompress

Easily extract zip, tar and tar.gz archives


Version published
Weekly downloads
2.3M
decreased by-18.69%
Maintainers
1
Install size
1.15 MB
Created
Weekly downloads
 

Package description

What is decompress?

The decompress npm package is a module that allows for decompressing archive files such as zip, tar, tar.gz, and many others. It provides a simple API to easily extract files from these archives.

What are decompress's main functionalities?

Extracting archive files

This feature allows you to extract files from an archive like a zip file into a specified directory. The 'decompress' function returns a promise that resolves with an array of file objects when the extraction is complete.

const decompress = require('decompress');

decompress('unicorn.zip', 'dist').then(files => {
    console.log('Files decompressed successfully');
});

Extracting specific files

This feature allows you to extract only specific files from an archive by using a filter function. The filter function is passed each file object, and you return a boolean to indicate whether the file should be extracted.

const decompress = require('decompress');

const filesToExtract = ['unicorn.png', 'rainbow.jpg'];

decompress('archive.zip', 'dist', {
    filter: file => filesToExtract.includes(file.path)
}).then(files => {
    console.log('Selected files decompressed successfully');
});

Using plugins to handle different archive types

The decompress package can be extended with plugins to support more archive types. In this example, the 'decompress-targz' plugin is used to decompress a '.tar.gz' file.

const decompress = require('decompress');
const decompressTargz = require('decompress-targz');

decompress('unicorn.tar.gz', 'dist', {
    plugins: [
        decompressTargz()
    ]
}).then(files => {
    console.log('tar.gz file decompressed successfully');
});

Other packages similar to decompress

Readme

Source

decompress Build Status

Easily extract .zip, .tar and .tar.gz archives

Install

$ npm install --save decompress

Usage

You'll only need to pass a type into ext and it'll figure the rest out for you.

var decompress = require('decompress');
var fs = require('fs');

fs.createReadStream('foo.tar.gz').pipe(decompress({ ext: '.tar.gz' }));

API

decompress(opts)

Extract an archive using the ext option to determine which extractor to use. If no path is specified it'll extract it to your current location.

decompress.canExtract(src, mime)

Determine if a file can be extracted or not by checking the file extension and/or the MIME type.

decompress.canExtract('foo.zip');
// => true

decompress.canExtract('application/zip');
// => true

Options

ext

Type: String
Default: ''

String that can be a file name, URL, MIME type etc.

path

Type: String
Default: process.cwd()

Path to extract the archive to. If no path is defined it'll extract it to your current location.

strip

Type: Number
Default: 0

Equivalent to --strip-components for tar.

CLI

$ npm install --global decompress
$ decompress --help

Usage
  $ decompress <file>
  $ cat <file> | decompress

Example
  $ decompress --out dist --strip 1 archive.zip
  $ cat files.txt | decompress --out dist

Options
  -o, --out <path>        Path to extract the archive to
  -s, --strip <number>    Strip path segments from root when extracting

License

MIT © Kevin Mårtensson

Keywords

FAQs

Last updated on 31 Aug 2014

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