Nodejs compressing files with archiver module

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.