本文介绍了处理管道完成的回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下 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.
更多推荐
处理管道完成的回调
发布评论