thrackle / express-zip

stream multiple files to the browser as a single zip, in pure node
MIT License
72 stars 18 forks source link

Write Stream into res.zip #9

Open CrackerakiUA opened 8 years ago

CrackerakiUA commented 8 years ago

This module looks so cool. Can you check my issue http://stackoverflow.com/questions/34168669/windows-azure-storage-blobs-to-zip-file-with-express ? Basically i am trying to read image from database via stream, and at the moment i am saving this stream in disk, then use res.zip. Is it possible to use directly stream to res.zip?

thrackle commented 8 years ago

Hi CrackerakiUA. It looks like you found the other issue where someone else suggested how to do this. You can see in this line of code that under the covers you can in fact pass a readStream directly:

https://github.com/thrackle/express-zip/blob/master/lib/express-zip.js#L55

So you are basically doing something like:

var zip = zipstream(exports.options);
zip.pipe(express.response || http.ServerResponse.prototype); // res is a writable stream

var addFile = function(file, cb) {
  zip.entry(fs.createReadStream(file.path), { name: file.name }, cb);
};

async.forEachSeries(files, addFile, function(err) {
  if (err) return cb(err);
  zip.finalize(function(bytesZipped) {
    cb(null, bytesZipped);
  });
});

Apologize if I've made horrible errors above; I haven't been on this for a bit.

thrackle commented 8 years ago

FWIW I've gone ahead and blocked off some time this Sunday for me to go through and get this added to the API, as well as close all the other PRs / issues. Glad this is helpful!

CrackerakiUA commented 8 years ago

Generally as i see we need to modify the plugin, which will create array of streams which user can use.

thrackle commented 8 years ago

I'll add support this weekend.

On Wed, Dec 9, 2015 at 11:53 AM, Honchar Denys notifications@github.com wrote:

Generally as i see we need to modify the plugin, which will create array of streams which user can use.

— Reply to this email directly or view it on GitHub https://github.com/thrackle/express-zip/issues/9#issuecomment-163356203.

CrackerakiUA commented 8 years ago

i will fork and try to add it.