2

我正在使用归档器创建一个 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");
4

1 回答 1

1

如果你在 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
    });

参考https://nodejs.org/api/child_process.html

于 2016-04-04T11:39:47.170 回答