Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在Nodejs中对zip文件进行密码保护?_Node.js_Node Archiver - Fatal编程技术网

Node.js 如何在Nodejs中对zip文件进行密码保护?

Node.js 如何在Nodejs中对zip文件进行密码保护?,node.js,node-archiver,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.

我正在使用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");

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

请参阅

Archiver不支持密码@prinzhorn:我可以使用crypto-then对zip文件进行密码保护吗?如果希望与zip兼容,则不支持。该文件只能由您的系统读取,而不能由第三方zip客户端读取。至少要相信原始人。