zip-stream is a streaming zip generator. It was built to be a successor to zipstream. Dependencies are kept to a minimum through the use of many of node's built-in modules including the use of zlib module for compression.
npm install zip-stream --save
You can also use npm install https://github.com/ctalkington/node-zip-stream/archive/master.tar.gz
to test upcoming versions.
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 that ease the so called "callback hell".
If you want a module that handles entry queueing and much more, you should check out archiver which uses this module internally.
var packer = require('zip-stream');
var archive = new packer(); // OR new packer(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) {
if (err) throw err;
archive.finalize();
});
Appends an input source (text string, buffer, or stream) to the instance. When the instance has received, processed, and emitted the input, the callback is fired.
Finalizes the instance. You should listen to the destination stream's end
/close
/finish
event to know when all output has been safely consumed.
Sets the zip comment.
If true, forces the file date and time to UTC. Helps with testing across timezones.
Passed to node's zlib module to control compression. Options may vary by node version.
Sets the entry name including internal path.
Sets the entry type. Defaults to file
. (allowed types to be expanded in future)
Sets the entry date. This can be any valid date string or instance. Defaults to current time in locale.
If true, entry contents will be stored without compression.
Sets the entry comment.
Sets the entry permissions. (experimental)
Concept inspired by Antoine van Wel's zipstream module, which is no longer being updated.