Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: antelle/node-stream-zip
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d0d58a799380238a2852b28c3c50c563e7b12e7a
Choose a base ref
...
head repository: antelle/node-stream-zip
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 82d55e0cde12d9916123b079c5a5291e4e954a38
Choose a head ref

Commits on Jan 30, 2019

  1. fix #37: migrated deprecated Buffer constructor

    antelle committed Jan 30, 2019
    Copy the full SHA
    907c887 View commit details

Commits on Jul 4, 2019

  1. Include LICENSE in published package

    The full license text was not included in the published
    version of the package (as required by the license) and
    the old filename was somewhat non-standard making it a
    bit difficult to automate collection of the third party
    licenses for EULAs etc. (also, as the license requires)
    DiscoNova committed Jul 4, 2019
    Copy the full SHA
    bc3d672 View commit details
  2. Bump version

    No code changes, bump patch level 1.8.0. => 1.8.1
    DiscoNova committed Jul 4, 2019
    Copy the full SHA
    0579faa View commit details
  3. Upgrade nodeunit to resolve known security vulnerabilities

    In nodeunit 0.9.1 there are 46 known security vulnerabilities
    (of which 11 are moderate and 14 are high severity) that have
    been fixed in 0.11.3
    DiscoNova committed Jul 4, 2019
    Copy the full SHA
    7115261 View commit details
  4. Merge pull request #42 from DiscoNova/wip/license-in-package

    Appeasing corporate legal department
    antelle authored Jul 4, 2019
    Copy the full SHA
    84525fe View commit details
  5. licence paths

    antelle committed Jul 4, 2019
    Copy the full SHA
    4a97931 View commit details
  6. Include LICENSE in published package

    The full license text was not included in the published
    version of the package (as required by the license) and
    the old filename was somewhat non-standard making it a
    bit difficult to automate collection of the third party
    licenses for EULAs etc. (also, as the license requires)
    DiscoNova authored and antelle committed Jul 4, 2019
    Copy the full SHA
    fba8338 View commit details
  7. Bump version

    No code changes, bump patch level 1.8.0. => 1.8.1
    DiscoNova authored and antelle committed Jul 4, 2019
    Copy the full SHA
    ccd88d6 View commit details
  8. licence paths

    antelle committed Jul 4, 2019
    Copy the full SHA
    ed8069a View commit details
  9. Merge branch 'DiscoNova-wip/security-audit'

    antelle committed Jul 4, 2019
    Copy the full SHA
    024f276 View commit details
  10. bump version

    antelle committed Jul 4, 2019
    Copy the full SHA
    0e2b93f View commit details

Commits on Oct 27, 2019

  1. Create FUNDING.yml

    antelle authored Oct 27, 2019
    Copy the full SHA
    c2eea6a View commit details

Commits on Jan 14, 2020

  1. fix #45: closing a file cancels all pending events

    antelle committed Jan 14, 2020
    2
    Copy the full SHA
    e453328 View commit details
  2. fixed callbacks in close()

    antelle committed Jan 14, 2020
    Copy the full SHA
    caad81b View commit details

Commits on Apr 28, 2020

  1. fixed close() when zip was not found

    sregger authored and gannons committed Apr 28, 2020
    Copy the full SHA
    577ed63 View commit details
  2. Merge pull request #48 from sregger/master

    fixed close() when zip was not found
    Dimitri Witkowski authored Apr 28, 2020
    Copy the full SHA
    087ee93 View commit details
  3. updated outdated packages

    antelle committed Apr 28, 2020
    Copy the full SHA
    ca9ca75 View commit details

Commits on May 1, 2020

  1. typescript interface

    antelle committed May 1, 2020
    2
    Copy the full SHA
    44718de View commit details
  2. added a missing file

    antelle committed May 1, 2020
    Copy the full SHA
    4d342ac View commit details

Commits on May 13, 2020

  1. removed deflate64

    antelle committed May 13, 2020
    Copy the full SHA
    4edf18f View commit details

Commits on May 15, 2020

  1. fixed typescript interface definition

    antelle committed May 15, 2020
    Copy the full SHA
    97304c6 View commit details

Commits on Jun 1, 2020

  1. Copy the full SHA
    060770d View commit details

Commits on Jun 2, 2020

  1. Merge pull request #53 from terite/fix-entries-typedef

    fix some typedefs related to entries
    Dimitri Witkowski authored Jun 2, 2020
    Copy the full SHA
    5311d56 View commit details
  2. bump version

    antelle committed Jun 2, 2020
    Copy the full SHA
    cd74e3d View commit details

Commits on Aug 14, 2020

  1. fix #58: parameter type

    antelle committed Aug 14, 2020
    Copy the full SHA
    0075767 View commit details
  2. release notes

    antelle committed Aug 14, 2020
    Copy the full SHA
    4824b70 View commit details

Commits on Oct 30, 2020

  1. Improve Typescript type definitions to allow use of ZipEntry and Stre…

    …amZipOptions types by consumers
    Brian Cort committed Oct 30, 2020
    Copy the full SHA
    7df2245 View commit details
  2. Improve Typescript type definitions to allow use of ZipEntry and Stre…

    …amZipOptions types by consumers
    Brian Cort committed Oct 30, 2020
    Copy the full SHA
    70f5287 View commit details
  3. Improve type definitions to include option of passing ZipEntry to fun…

    …ctions that take strings
    Brian Cort committed Oct 30, 2020
    Copy the full SHA
    36116c0 View commit details

Commits on Oct 31, 2020

  1. Merge pull request #64 from thatcort/master

    Improved Typescript Type Definitions
    Dimitri Witkowski authored Oct 31, 2020
    Copy the full SHA
    76f2c0e View commit details
  2. bump version

    antelle committed Oct 31, 2020
    Copy the full SHA
    a11f251 View commit details
  3. release notes

    antelle committed Oct 31, 2020
    Copy the full SHA
    4e73b6d View commit details

Commits on Nov 3, 2020

  1. Remove unnecessary module declaration

    Brian Cort committed Nov 3, 2020
    Copy the full SHA
    9cd18a9 View commit details
  2. Merge pull request #65 from thatcort/master

    Remove unnecessary module declaration
    Dimitri Witkowski authored Nov 3, 2020
    Copy the full SHA
    7bbcbaa View commit details
  3. bump version

    antelle committed Nov 3, 2020
    Copy the full SHA
    7c4a4b2 View commit details
  4. release notes

    antelle committed Nov 3, 2020
    Copy the full SHA
    eb95d50 View commit details

Commits on Nov 4, 2020

  1. Copy the full SHA
    c244f3b View commit details
  2. Merge pull request #66 from thatcort/master

    Add missing 'declare' keyword to typescript definitions
    Dimitri Witkowski authored Nov 4, 2020
    Copy the full SHA
    4edc022 View commit details
  3. bump version

    antelle committed Nov 4, 2020
    Copy the full SHA
    e78f24c View commit details

Commits on Nov 6, 2020

  1. Add declare keyword

    Brian Cort committed Nov 6, 2020
    Copy the full SHA
    f75312a View commit details
  2. added d.ts validation

    antelle committed Nov 6, 2020
    Copy the full SHA
    39ebe6e View commit details
  3. Merge pull request #67 from thatcort/master

    Add declare keyword
    Dimitri Witkowski authored Nov 6, 2020
    Copy the full SHA
    9ac8a12 View commit details
  4. bump version

    antelle committed Nov 6, 2020
    Copy the full SHA
    97d9f2a View commit details

Commits on Nov 15, 2020

  1. added an option to pass fd instead of file name

    antelle committed Nov 15, 2020
    Copy the full SHA
    941e126 View commit details

Commits on Nov 28, 2020

  1. migrated to GitHub actions

    antelle committed Nov 28, 2020
    Copy the full SHA
    d005f2e View commit details
  2. badge

    antelle committed Nov 28, 2020
    Copy the full SHA
    e4cf513 View commit details

Commits on Jan 28, 2021

  1. fixed an inspection finding

    antelle committed Jan 28, 2021
    Copy the full SHA
    168b0d9 View commit details

Commits on Feb 5, 2021

  1. modernized the javascript

    antelle committed Feb 5, 2021
    Copy the full SHA
    eed57a1 View commit details
  2. fix #52: async API

    antelle committed Feb 5, 2021
    Copy the full SHA
    51e0ed9 View commit details
  3. moved examples in readme

    antelle committed Feb 5, 2021
    Copy the full SHA
    3eb8963 View commit details
Showing with 7,592 additions and 845 deletions.
  1. +30 −0 .eslintrc
  2. +12 −0 .github/FUNDING.yml
  3. +27 −0 .github/workflows/ci-checks.yaml
  4. +5 −0 .prettierrc
  5. +0 −14 .travis.yml
  6. +1 −1 MIT-LICENSE.txt → LICENSE
  7. +98 −15 README.md
  8. +35 −0 example-async.js
  9. +47 −0 example-callbacks.js
  10. +0 −28 example.js
  11. +193 −0 node_stream_zip.d.ts
  12. +806 −644 node_stream_zip.js
  13. +5,995 −0 package-lock.json
  14. +15 −3 package.json
  15. +73 −0 release-notes.md
  16. BIN test/{ok → err}/deflate64.zip
  17. +255 −140 test/tests.js
30 changes: 30 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2020
},
"env": {
"node": true,
"es6": true
},
"rules": {
"no-var": "error",
"prefer-const": "error",
"curly": "error",
"eqeqeq": "error",
"prefer-arrow-callback": "error",
"no-new-object": "error",
"object-shorthand": "error",
"no-array-constructor": "error",
"array-callback-return": "error",
"no-eval": "error",
"no-new-func": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"no-useless-constructor": "error",
"no-dupe-class-members": "error",
"no-duplicate-imports": "error",
"no-unneeded-ternary": "error",
"no-console": "error"
}
}
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: antelle
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
27 changes: 27 additions & 0 deletions .github/workflows/ci-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI Checks
on:
push:
branches:
- master
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: NPM install
run: npm ci
- name: Lint
run: npm run lint
- name: Check types
run: npm run check-types
- name: Run tests
run: npm test
- name: Setup Node.js 10
uses: actions/setup-node@v2
with:
node-version: '10'
- name: Run tests on Node.js 10
run: npm test
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 4,
"printWidth": 100,
"singleQuote": true
}
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion MIT-LICENSE.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 Antelle https://github.com/antelle
Copyright (c) 2021 Antelle https://github.com/antelle

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
113 changes: 98 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# node-stream-zip [![Build status](https://travis-ci.org/antelle/node-stream-zip.svg?branch=master)](https://travis-ci.org/antelle/node-stream-zip)
# node-stream-zip ![CI Checks](https://github.com/antelle/node-stream-zip/workflows/CI%20Checks/badge.svg)

node.js library for reading and extraction of ZIP archives.
Features:
@@ -9,22 +9,103 @@ Features:
- fast initialization
- no dependencies, no binary addons
- decompression with built-in zlib module
- deflate, deflate64, sfx, macosx/windows built-in archives
- deflate, sfx, macosx/windows built-in archives
- ZIP64 support

# Installation
## Installation

`$ npm install node-stream-zip`
```sh
npm i node-stream-zip
```

## Usage

There are two APIs provided:
1. [promise-based / async](#async-api)
2. [callbacks](#callback-api)

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

# Usage
### Async API

Open a zip file
```javascript
const StreamZip = require('node-stream-zip');
const zip = new StreamZip({
file: 'archive.zip',
storeEntries: true
const zip = new StreamZip.async({ file: 'archive.zip' });
```

Stream one entry to stdout
```javascript
const stm = await zip.stream('path/inside/zip.txt');
stm.pipe(process.stdout);
stm.on('end', () => zip.close());
```

Read a file as buffer
```javascript
const data = await zip.entryData('path/inside/zip.txt');
await zip.close();
```

Extract one file to disk
```javascript
await zip.extract('path/inside/zip.txt', './extracted.txt');
await zip.close();
```

List entries
```javascript
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
```javascript
fs.mkdirSync('extracted');
await zip.extract('path/inside/zip/', './extracted');
await zip.close();
```

Extract everything
```javascript
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
```javascript
zip.on('extract', (entry, file) => {
console.log(`Extracted ${entry.name} to ${file}`);
});
```

`entry` event is generated for every entry during loading
```javascript
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
```javascript
const StreamZip = require('node-stream-zip');
const zip = new StreamZip({ file: 'archive.zip' });

// Handle errors
zip.on('error', err => { /*...*/ });
@@ -39,7 +120,7 @@ zip.on('ready', () => {
console.log(`Entry ${entry.name}: ${desc}`);
}
// Do not forget to close the file once you're done
zip.close()
zip.close();
});
```

@@ -109,30 +190,32 @@ zip.on('entry', entry => {
});
```

# Options
## 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
## 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
## Building

The project doesn't require building. To run unit tests with [nodeunit](https://github.com/caolan/nodeunit):
`$ npm test`
```sh
npm test
```

# Known issues
## Known issues

- [utf8](https://github.com/rubyzip/rubyzip/wiki/Files-with-non-ascii-filenames) file names
- AES encrypted files

# Contributors
## Contributors

ZIP parsing code has been partially forked from [cthackers/adm-zip](https://github.com/cthackers/adm-zip) (MIT license).
35 changes: 35 additions & 0 deletions example-async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable no-console,no-unused-vars */
const StreamZip = require('./');

(async () => {
console.log('Loading zip...');

const zip = new StreamZip.async({ file: './test/ok/normal.zip' });
const entriesCount = await zip.entriesCount;

console.log(`Done in ${process.uptime()}s. Entries read: ${entriesCount}`);

const entry = await zip.entry('README.md');
console.log('Entry for README.md:', entry);

const data = await zip.entryData('README.md');
const firstLine = data.toString().split('\n')[0].trim();
console.log(`First line of README.md: "${firstLine}"`);

async function streamDataToStdOut() {
const stm = await zip.stream('README.md');
console.log('README.md contents streamed:\n');
stm.pipe(process.stdout);
}

async function extractEntry() {
await zip.extract('README.md', './tmp');
}

async function extractAll() {
const extracted = await zip.extract(null, './tmp');
console.log(`Extracted ${extracted} entries`);
}

await zip.close();
})().catch(console.error);
47 changes: 47 additions & 0 deletions example-callbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable no-console,no-unused-vars */
const StreamZip = require('./');

const zip = new StreamZip({ file: './test/ok/normal.zip' });
zip.on('error', (err) => {
console.error('ERROR: ' + err);
});
zip.on('ready', () => {
const entriesCount = zip.entriesCount;
console.log(`Done in ${process.uptime()}s. Entries read: ${entriesCount}`);

const entry = zip.entry('README.md');
console.log('Entry for README.md:', entry);

const data = zip.entryDataSync('README.md');
const firstLine = data.toString().split('\n')[0].trim();
console.log(`First line of README.md: "${firstLine}"`);

zip.close();

function streamDataToStdOut() {
zip.stream('README.md', (err, stm) => {
if (err) {
return console.error(err);
}
console.log('README.md contents streamed:\n');
stm.pipe(process.stdout);
});
}

function extractEntry() {
zip.extract('README.md', './tmp', (err) => {
console.log(err ? err : 'Entry extracted');
zip.close();
});
}

function extractAll() {
zip.extract(null, './tmp', (err, count) => {
console.log(err ? err : `Extracted ${count} entries`);
zip.close();
});
}
});
zip.on('extract', (entry, file) => {
console.log('extract', entry.name, file);
});
28 changes: 0 additions & 28 deletions example.js

This file was deleted.

Loading