Router.get ('/download/qiantu ', function (req,res) {var dirname = (new Date ()). GetTime () var zippath = './down/' +dirname+ ' . zip ' var output = Fs.createwritestream (Zippath) var ziparchiver = archiver (' Zip ', {store:true}) ziparchiver.pipe (output ) async.mapseries (Req.session.qtimagesurl,function (item, callback) {//Asynchronous download setTimeout (function () { // Downloadpic (item, dir+ '/' + (new Date ()). GetTime () + '. jpg '); Ziparchiver.append (Request Item), {' name ': ' images/' + (new Date ()). GetTime () + '. jpg '}) callback (null, item); } }, function (err, results) {Req.session.qtimagesurl =[]//After download is complete, empty ziparchiver.finalize () res.render (' Index ')})
Request for a remote picture file, local file is used Fs.createreadstream
Item is a picture path
var output = Fs.createwritestream (Zippath) This is the compressed file name
{' name ': ' images/' + (new Date ()). GetTime () + '. jpg '}
Compressed file name after decompression,/before the corresponding folder will be automatically produced
Ziparchiver.finalize () End operation
Nodejs compressing files with archiver module