下载图像后的回调功能 [英] Callback function after image has downloaded
本文介绍了下载图像后的回调功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用请求模块保存图像下载.有了
I'm trying to save an image download with the request module. With this
request('http://google.com/images/logos/ps_logo2.png').pipe(fs.createWriteStream('doodle.png'));
工作正常. 但是,我希望能够在图像完全下载后执行其他操作. 如何为fs.createWriteStream提供回调函数?
It works fine. But I want to be able to do something else after the image has been completely downloaded. How can provide a callback function to fs.createWriteStream ?
推荐答案
您要提前创建流,然后在close事件上执行某些操作.
You want to create the stream ahead of time and then do something on the close event.
var picStream = fs.createWriteStream('doodle.png');
picStream.on('close', function() {
console.log('file done');
});
request('http://google.com/images/logos/ps_logo2.png').pipe(picStream);
这应该做到.
这篇关于下载图像后的回调功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文