Node流中的结束事件和结束事件有什么区别 [英] What's the difference between end and finish events in Node streams
问题描述
Node.js流同时触发end
和finish
事件.两者有什么区别?
Node.js streams triggers both end
and finish
events. What's the difference between both?
推荐答案
end
和finish
是在不同类型的流上的相同事件,但
end
and finish
are the same event BUT on different types of Streams.
-
stream.Readable
仅触发end
,从不触发finish
-
stream.Writable
仅触发finish
,永不触发end
stream.Readable
fires ONLYend
and NEVERfinish
stream.Writable
fires ONLYfinish
and NEVERend
来源: https://nodejs.org/dist/latest-v5.x /docs/api/stream.html
为什么同一事件的命名不同?
我能想到的唯一原因是因为双工流(stream.Duplex
)同时实现了stream.Readable
和stream.Writable
接口(
The only reason I could think of is because of duplex streams (stream.Duplex
), which implement both stream.Readable
and stream.Writable
interfaces (https://nodejs.org/dist/latest-v5.x/docs/api/stream.html#stream_class_stream_duplex) are readable and writable stream at the same time. To differentiate between end of reading and end of writing on the stream you must have a different event fired. SO, for Duplex streams end
is end of reading and finish
is end of writing.
这篇关于Node流中的结束事件和结束事件有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!