3

I am creating a zip file using archiver. below is my code to do it. I need to password protect it. How can I do it?

var head={'Content-Type':'application/octet-stream','Content-disposition':'attachment; filename='+zipName,'Transfer-Encoding':'chunked' }

res.writeHead(200,head);

var archive = archiver('zip');

archive.pipe(res);

archive.append(result, { name: attachment.aliasFileName });

archive.finalize();

return res.send("thanks");
node_modules
  • 4,790
  • 6
  • 21
  • 37
user3677779
  • 41
  • 1
  • 4

1 Answers1

1

If you are working in linux you can do some thing like this

 //create a zip 
    spawn = require('child_process').spawn;
    zip = spawn('zip',['-P', 'password' , 'archive.zip', 'complete path to archive file']);
    zip .on('exit', function(code) {
    ...// Do something with zipfile archive.zip
    ...// which will be in same location as file/folder given
    });

Refer https://nodejs.org/api/child_process.html

abhilash
  • 827
  • 11
  • 20