在nodejs中解压缩文件夹时无效的签名错误

我使用unzip节点模块解压缩我的binary-data (来自request模块)。 当request模块的response不包含zip文件夹binary data (如果响应没有zip文件夹数据,其他二进制数据),在某些情况下失败。

我如何处理这个例外。

 const request = require("request"); const unzip = require('unzip'); const stream = require('stream'); var options = { method: 'GET', url: /*URL*/, encoding: null }; request(options, function (error, response, body) { zipExtract(error, body); }); 

zipExtract:

 function zipExtract(error, zipData) { if (error) { console.error(error); } else { try { //create stream object var artifactStream = new stream.PassThrough(); //parse buffer into stream artifactStream.end(zipData); //pipe response to unzip artifactStream.pipe(unzip.Extract({path: 'app/output'})); } catch (exception) { console.error(exception); } } } 

它会在控制台上提示错误

 events.js:160 throw er; // Unhandled 'error' event ^ Error: invalid signature: 0x6d74683c at C:\app-hub\module-application-size\node_modules\unzip\lib\parse.js:63:13 at runCallback (timers.js:637:20) at tryOnImmediate (timers.js:610:5) at processImmediate [as _immediateCallback] (timers.js:582:5) npm ERR! Test failed. See above for more details. 

Solutions Collecting From Web of "在nodejs中解压缩文件夹时无效的签名错误"