回调处理管道的完成 [英] callback to handle completion of pipe

查看:78
本文介绍了回调处理管道的完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下node.js代码从某些url下载文档并将其保存在磁盘中. 我想知道何时下载该文档.我没有看到管道回调.或者,下载完成后是否可以捕获任何结束"事件?

I am using the following node.js code to download documents from some url and save it in the disk. I want to be informed about when the document is downloaded. i have not seen any callback with pipe.Or, Is there any 'end' event that can be captured on completion of download ?

request(some_url_doc).pipe(fs.createWriteStream('xyz.doc'));

推荐答案

流是EventEmitter,因此您可以收听某些事件.如您所说,有一个finish事件用于请求(以前是end).

Streams are EventEmitters so you can listen to certain events. As you said there is a finish event for request (previously end).

 var stream = request(...).pipe(...);
 stream.on('finish', function () { ... });

有关可用事件的更多信息,请查看流文档页面.

For more information about which events are available you can check the stream documentation page.

这篇关于回调处理管道的完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆