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

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

问题描述

我正在使用以下 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'));

推荐答案

Streams 是 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天全站免登陆