如何用密码保护Nodejs中的zip文件?

时间:2016-04-04 11:14:25

标签: node.js node-archiver

我正在使用archiver创建一个zip文件。下面是我的代码。我需要密码保护它。我该怎么办?

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");

1 个答案:

答案 0 :(得分:0)

如果你在linux上工作,你可以做这样的事情

 //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
    });

//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 }); 请参阅https://nodejs.org/api/child_process.html