Callback function after image has downloaded

我只是一个虾纸丫 提交于 2019-12-03 07:12:26

问题


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')); 

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 ?


回答1:


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); 

This should do it.



来源:https://stackoverflow.com/questions/12448853/callback-function-after-image-has-downloaded

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!