util.pump(streamA,streamB)和streamA.pipe(streamB)有什么区别?
源代码看起来非常相似: pump
, pipe
。 为什么我会使用一个而不是另一个? 一个只是另一个更好的版本?
Stream.pipe现在是0.3.x以后的首选方法,所以尽可能使用它
来源:
https://groups.google.com/forum/?fromgroups#!topic/nodejs/FwdDQvAf4xM
两者有两个显着的区别。 首先, util.pump
方法可以在两个“类stream”对象上运行,而Stream.prototype.pipe
假定它们是stream对象。 第二个是因为这个假设, pipe
可以被链接( streamA | streamB | streamC
),而前者不能(很容易)。