README.md
 1  # ZipStream
 2  
 3  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.
 4  
 5  It was originally created to be a successor to [zipstream](https://npmjs.org/package/zipstream).
 6  
 7  Visit the [API documentation](http://archiverjs.com/zip-stream) for a list of all methods available.
 8  
 9  ### Install
10  
11  ```bash
12  npm install zip-stream --save
13  ```
14  
15  You can also use `npm install https://github.com/archiverjs/node-zip-stream/archive/master.tar.gz` to test upcoming versions.
16  
17  ### Usage
18  
19  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".
20  
21  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.
22  
23  ```js
24  const Packer = require('zip-stream');
25  const archive = new Packer(); // OR new Packer(options)
26  
27  archive.on('error', function(err) {
28    throw err;
29  });
30  
31  // pipe archive where you want it (ie fs, http, etc)
32  // listen to the destination's end, close, or finish event
33  
34  archive.entry('string contents', { name: 'string.txt' }, function(err, entry) {
35    if (err) throw err;
36    archive.entry(null, { name: 'directory/' }, function(err, entry) {
37      if (err) throw err;
38      archive.finish();
39    });
40  });
41  ```
42  
43  ## Credits
44  
45  Concept inspired by Antoine van Wel's [zipstream](https://npmjs.org/package/zipstream) module, which is no longer being updated.