下载后的压缩文件的响应后,我需要调用另一个函数ProcessZip文件。但我无法在.send()
后触发功能ProcessZipFile()
:功能如何调派往节点JS
app.get('/', function (req, res) {
DownloadZipFile();
});
function DownloadZipFile() {
var file = fs.createWriteStream('./tmp/student.tar.gz');
s3.getObject(params
.on('httpData', function (chunk) {
file.write(chunk);
})
.on('httpDone', function() {
file.end();
})
.send();
}
function ProcessZipFile() {
//.....
}
你可以注意到 “[回调地狱(http://callbackhell.com/)” 通过嵌套回调函数创建。要解决这个问题,你可以[使用'async'库或'Promise'(https://ciphertrick.com/2016/06/12/avoiding-callback-hell-node-js/),或['异步/在ES7中等待“](http://rossboucher.com/await)功能。 –