All Projects → antelle → Node Stream Zip

antelle / Node Stream Zip

Licence: other
node.js library for fast reading of large ZIPs

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Node Stream Zip

lrkFM
Awesome, (ad) free, open source file manager for Android
Stars: ✭ 44 (-82.54%)
Mutual labels:  zip
python-zipstream
Like Python's ZipFile module, except it works as a generator that provides the file in many small chunks.
Stars: ✭ 117 (-53.57%)
Mutual labels:  zip
cracker-ng
ZIP cracker, CCRYPT cracker, and others to come.
Stars: ✭ 60 (-76.19%)
Mutual labels:  zip
laravel-backup-shield
🔒Password protection (and encryption) for your laravel backups.
Stars: ✭ 32 (-87.3%)
Mutual labels:  zip
ToGoZip
Android share/sendTo menu implementation "add2Zip"
Stars: ✭ 44 (-82.54%)
Mutual labels:  zip
ZipWriter
Library for creating ZIP archive for Lua
Stars: ✭ 15 (-94.05%)
Mutual labels:  zip
box
Box - Open Standard Archive Format, a zip killer.
Stars: ✭ 38 (-84.92%)
Mutual labels:  zip
lzbase62
LZ77(LZSS) based compression algorithm in base62 for JavaScript.
Stars: ✭ 38 (-84.92%)
Mutual labels:  zip
aspZip
A classic ASP zip and unzip utility class that uses the native zip support from Windows (XP and above) - no components needed
Stars: ✭ 24 (-90.48%)
Mutual labels:  zip
epub-package.dart
A dart package to parse EPUB files
Stars: ✭ 21 (-91.67%)
Mutual labels:  zip
zip-bucket
zips files in a Google Cloud Storage [tm] bucket
Stars: ✭ 32 (-87.3%)
Mutual labels:  zip
rc-zip
Pure rust zip & zip64 reading and writing
Stars: ✭ 93 (-63.1%)
Mutual labels:  zip
zipread
Fast and memory efficient ZIP reader for Node.js
Stars: ✭ 12 (-95.24%)
Mutual labels:  zip
bled
Base Library for Easy Decompression
Stars: ✭ 21 (-91.67%)
Mutual labels:  zip
uncompress.js
Uncompress ZIP, RAR, and TAR files with pure JavaScript
Stars: ✭ 79 (-68.65%)
Mutual labels:  zip
zipadee
A web app for viewing/editing the contents of a ZIP file
Stars: ✭ 15 (-94.05%)
Mutual labels:  zip
zip
PHP ZipArchive toolbox
Stars: ✭ 30 (-88.1%)
Mutual labels:  zip
tiny-zip
The missing Zip library for Java
Stars: ✭ 18 (-92.86%)
Mutual labels:  zip
cross-unzip
Cross-platform 'native' unzip in Node.js
Stars: ✭ 17 (-93.25%)
Mutual labels:  zip
ZipCrack
Crack password protected zip files
Stars: ✭ 23 (-90.87%)
Mutual labels:  zip

node-stream-zip CI Checks

node.js library for reading and extraction of ZIP archives.
Features:

  • it never loads entire archive into memory, everything is read by chunks
  • large archives support
  • all operations are non-blocking, no sync i/o
  • fast initialization
  • no dependencies, no binary addons
  • decompression with built-in zlib module
  • deflate, sfx, macosx/windows built-in archives
  • ZIP64 support

Installation

npm i node-stream-zip

Usage

There are two APIs provided:

  1. promise-based / async
  2. callbacks

It's recommended to use the new, promise API, however the legacy callback API may be more flexible for certain operations.

Async API

Open a zip file

const StreamZip = require('node-stream-zip');
const zip = new StreamZip.async({ file: 'archive.zip' });

Stream one entry to stdout

const stm = await zip.stream('path/inside/zip.txt');
stm.pipe(process.stdout);
stm.on('end', () => zip.close());

Read a file as buffer

const data = await zip.entryData('path/inside/zip.txt');
await zip.close();

Extract one file to disk

await zip.extract('path/inside/zip.txt', './extracted.txt');
await zip.close();

List entries

const entriesCount = await zip.entriesCount;
console.log(`Entries read: ${entriesCount}`);

const entries = await zip.entries();
for (const entry of Object.values(entries)) {
    const desc = entry.isDirectory ? 'directory' : `${entry.size} bytes`;
    console.log(`Entry ${entry.name}: ${desc}`);
}

// Do not forget to close the file once you're done
await zip.close();

Extract a folder from archive to disk

fs.mkdirSync('extracted');
await zip.extract('path/inside/zip/', './extracted');
await zip.close();

Extract everything

fs.mkdirSync('extracted');
const count = await zip.extract(null, './extracted');
console.log(`Extracted ${count} entries`);
await zip.close();

When extracting a folder, you can listen to extract event

zip.on('extract', (entry, file) => {
    console.log(`Extracted ${entry.name} to ${file}`);
});

entry event is generated for every entry during loading

zip.on('entry', entry => {
    // you can already stream this entry,
    // without waiting until all entry descriptions are read (suitable for very large archives)
    console.log(`Read entry ${entry.name}`);
});

Callback API

Open a zip file

const StreamZip = require('node-stream-zip');
const zip = new StreamZip({ file: 'archive.zip' });

// Handle errors
zip.on('error', err => { /*...*/ });

List entries

zip.on('ready', () => {
    console.log('Entries read: ' + zip.entriesCount);
    for (const entry of Object.values(zip.entries())) {
        const desc = entry.isDirectory ? 'directory' : `${entry.size} bytes`;
        console.log(`Entry ${entry.name}: ${desc}`);
    }
    // Do not forget to close the file once you're done
    zip.close();
});

Stream one entry to stdout

zip.on('ready', () => {
    zip.stream('path/inside/zip.txt', (err, stm) => {
        stm.pipe(process.stdout);
        stm.on('end', () => zip.close());
    });
});

Extract one file to disk

zip.on('ready', () => {
    zip.extract('path/inside/zip.txt', './extracted.txt', err => {
        console.log(err ? 'Extract error' : 'Extracted');
        zip.close();
    });
});

Extract a folder from archive to disk

zip.on('ready', () => {
    fs.mkdirSync('extracted');
    zip.extract('path/inside/zip/', './extracted', err => {
        console.log(err ? 'Extract error' : 'Extracted');
        zip.close();
    });
});

Extract everything

zip.on('ready', () => {
    fs.mkdirSync('extracted');
    zip.extract(null, './extracted', (err, count) => {
        console.log(err ? 'Extract error' : `Extracted ${count} entries`);
        zip.close();
    });
});

Read a file as buffer in sync way

zip.on('ready', () => {
    const data = zip.entryDataSync('path/inside/zip.txt');
    zip.close();
});

When extracting a folder, you can listen to extract event

zip.on('extract', (entry, file) => {
    console.log(`Extracted ${entry.name} to ${file}`);
});

entry event is generated for every entry during loading

zip.on('entry', entry => {
    // you can already stream this entry,
    // without waiting until all entry descriptions are read (suitable for very large archives)
    console.log(`Read entry ${entry.name}`);
});

Options

You can pass these options to the constructor

  • storeEntries: true - you will be able to work with entries inside zip archive, otherwise the only way to access them is entry event
  • skipEntryNameValidation: true - by default, entry name is checked for malicious characters, like ../ or c:\123, pass this flag to disable validation errors

Methods

  • zip.entries() - get all entries description
  • zip.entry(name) - get entry description by name
  • zip.stream(entry, function(err, stm) { }) - get entry data reader stream
  • zip.entryDataSync(entry) - get entry data in sync way
  • zip.close() - cleanup after all entries have been read, streamed, extracted, and you don't need the archive

Building

The project doesn't require building. To run unit tests with nodeunit:

npm test

Known issues

  • utf8 file names
  • AES encrypted files

Contributors

ZIP parsing code has been partially forked from cthackers/adm-zip (MIT license).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].