node.js - Nodejs - Shortage of file size on nodejs archiver and fs stat -


the logic of program follow:

  1. get object aws s3
  2. zip object obtained s3 ( create zip file called a.zip )
  3. put z.aip file s3

now face problem a.zip file lack of few bytes. following code snippet, result of console.log(archive.pointer()) , console.log(stat.size) different. have idea ? thank you.

async.map(filename, util.gets3obj, function(err, result) {    var archiver = require('archiver');    var archive = archiver.create('zip', {});    archive.pipe(fs.createwritestream('./tmp/archive.zip'));    for(var i=0 ; i<result.length ; i++) {       archive.append(result[i], {name: filenamearr[i]});    }    archive.finalize();     archive.on('end', function() {      console.log(archive.pointer());      fs.stat('./tmp/archive.zip', function(err, stat) {         if(err) {}         console.log(stat.size);           });     }); }) 

i solve problem checking file size in close event of createwritestream without using end event of archive. because in end event of archive, writefilestream not finish.

var out = fs.createwritestream('archive.zip'); out.on('close', function() {     // check file size here ... }); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -