I make requests for files using the request module.

And how to make each query result (file) recorded in a zip archive immediately using streams and channels?

(To, without temporarily saving to a file on disk, adding to the archive and deleting later).

Something like this: rq.pipe (gzip). Pipe (wstream);

function downloadImage(url, idx, callback){ var dst = __dirname + "/uploads/"+req.body.Id+".gz"; var wstream = fs.createWriteStream(dst); var gzip = zlib.createGzip(); var rq = request(url); rq.on('error', function (err) { if (err.code === 'ETIMEDOUT') { console.log("ERRORR!!"); rq.end(); callback(err.code); }}); wstream.on("finish", function() { console.log(".on(finish " + idx + " " + dst); rq.end(); callback(dst); }) rq.pipe(gzip).pipe(wstream); } 

But in this my code, if there are a lot of files, they will be written glued together .. And I need that in a normal way .. each file is written separately, all in one archive.

How to do this? Can others have modules instead of zlib?

  • First, you need to change the format of the archive. Archives in gzip format can contain only 1 file. - Pavel Mayorov
  • Yes, it does not matter. Module Any other one could be used .. I just can not understand how to immediately write to the archive this stream from the url. I tried var archiver = require ('archiver'); but it’s also not clear there: archive.append is doing and cheto is worth everything - don’t write anything .. Dick, understand it .. - LS2010
  • No, this is just important. - Pavel Mayorov
  • Yes, none ... Well, in this module var archiver = require ('archiver'); The format of the zip archive is set .. All the norms are written to the files .. but I am more interested in "HOW to immediately write to the zip-archive through the pipe and streams .." Not to read and add from the file on the disk, but immediately the result of the response .. directly redirect to archive. AS? - LS2010
  • @ LS2010 See node-zip-stream - Save14

0