npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unzip-simple

v1.0.4

Published

Super-simple unzip-to-memory API with file globbing

Downloads

411

Readme

unzip-simple

A super-simple unzip API that simplifies file extraction...

import unzip from 'unzip-simple';
const [file] = await unzip('single-file-example.zip');
console.log(file.buffer.toString());

Filter files by applying a file globbing pattern...

const files = await unzip({input: 'multi-file-example.zip', filter: '*.txt'});

Usage Examples

Extract all files from a ZIP archive on disc...

import unzip from 'unzip-simple';
const files = await unzip('example.zip');
for (const file of files)
    console.log(file.name, file.buffer.toString());

Extract all files from a downloaded ZIP archive...

import unzip from 'unzip-simple';
import fetch from 'node-fetch';
const response = await fetch('https://github.com/davetemplin/unzip-simple/raw/master/test/example1.zip');
const buffer = await response.buffer();
const files = await unzip(buffer);

Obtain a directory listing from a ZIP archive without performing any file extraction...

import unzip from 'unzip-simple';
const files = await unzip({input: 'example.zip', extract: false});
for (const file of files)
    console.log(file.name, file.compressed, file.uncompressed);
foo.txt 208 330
bar.txt 148 213
...

Extract a specific file...

const files = await unzip({input: 'example.zip', filter: 'foo/bar.txt'});

Extract only text files...

const files = await unzip({input: 'example.zip', filter: '*.txt'});

Extract all files except images...

const files = await unzip({input: 'example.zip', filter: '!*.jpg'});

API

The API for this library is defined by a single function that accepts a set of options and returns an array of files in the ZIP archive. Alternatively, just the path or buffer of the ZIP archive can be passed as the input.

Function

unzip(options: UnzipOptions|string|Buffer|number): Promise<UnzipFile[]>

UnzipOptions

The options specify the input ZIP archive file, an optional filter to target specific files, and a flag that determines whether to extract files.

option | type | description ------- | ---------------------- | --- input | string|Buffer|number | Specifies the input ZIP archive file. Can be a path to a file, an in-memory buffer, or a file-descriptor. extract | boolean | Determines whether files are to be extracted from the ZIP archive. Use true to extract files or false to obtain a directory listing of the ZIP archive. (default=true) filter | string | Filters files from the ZIP archive. Any valid file globbing pattern can be used. If not specified, all files are included by default.

UnzipFile

The API returns an array of files, where each file contains the name and content for each extracted file along with the compressed and uncompressed file size.

attribute | type | description ------------ | -------- | --- name | string | File-name of the file within the ZIP archive. buffer | Buffer | A buffer containing the data extracted from the file in the ZIP archive. Use buffer.toString() to convert to text. compressed | number | Compressed size of the file (in bytes). uncompressed | number | Uncompressed size of the file (in bytes).

This API is intended for handling light-weight data extraction that can be easily held in-memory. If dealing with very large archives is a requirement, a lower level streaming interface like the one provided in yauzl should be used instead.