https://github.com/archiverjs/node-zip-stream
a streaming zip archive generator
https://github.com/archiverjs/node-zip-stream
Last synced: about 1 year ago
JSON representation
a streaming zip archive generator
- Host: GitHub
- URL: https://github.com/archiverjs/node-zip-stream
- Owner: archiverjs
- License: mit
- Created: 2014-01-06T00:38:52.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2025-04-14T05:49:29.000Z (over 1 year ago)
- Last Synced: 2025-04-28T02:37:22.947Z (about 1 year ago)
- Language: JavaScript
- Homepage: http://archiverjs.com/zip-stream
- Size: 607 KB
- Stars: 159
- Watchers: 8
- Forks: 23
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ZipStream
zip-stream is a streaming zip archive generator based on the `ZipArchiveOutputStream` prototype found in the [compress-commons](https://www.npmjs.org/package/compress-commons) project.
It was originally created to be a successor to [zipstream](https://npmjs.org/package/zipstream).
Visit the [API documentation](http://archiverjs.com/zip-stream) for a list of all methods available.
### Install
```bash
npm install zip-stream --save
```
You can also use `npm install https://github.com/archiverjs/node-zip-stream/archive/master.tar.gz` to test upcoming versions.
### Usage
This module is meant to be wrapped internally by other modules and therefore lacks any queue management. This means you have to wait until the previous entry has been fully consumed to add another. Nested callbacks should be used to add multiple entries. There are modules like [async](https://npmjs.org/package/async) that ease the so called "callback hell".
If you want a module that handles entry queueing and much more, you should check out [archiver](https://npmjs.org/package/archiver) which uses this module internally.
```js
import { ZipStream } from "zip-stream":
const archive = new ZipStream(); // OR new ZipStream(options)
archive.on("error", function (err) {
throw err;
});
// pipe archive where you want it (ie fs, http, etc)
// listen to the destination's end, close, or finish event
archive.entry("string contents", { name: "string.txt" }, function (err, entry) {
if (err) throw err;
archive.entry(null, { name: "directory/" }, function (err, entry) {
if (err) throw err;
archive.finish();
});
});
```
## Credits
Concept inspired by Antoine van Wel's [zipstream](https://npmjs.org/package/zipstream) module, which is no longer being updated.