处理管道完成的回调

编程入门 行业动态 更新时间:2024-10-23 13:26:59
本文介绍了处理管道完成的回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下 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.

更多推荐

处理管道完成的回调

本文发布于:2023-11-25 04:04:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回调   管道

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!