nodejs stream

参考 nodejs stream 手册
英文原版stream-handbook

Streams come to us from the earliest days of unix and have proven themselves over the decades as a dependable way to compose large systems out of small components that do one thing well.
You can then plug the output of one stream to the input of another and use libraries that operate abstractly on streams to institute higher-level flow control.

basic

there are 5 kinds of streams:readable,writable,transform,duplex ,and "classic"


pipe

All the different types of streams use .pipe() to pair inputs with outputs.
.pipe() is just a function that takes a readable source stream src and hooks the output to a destination writable stream dst
src.pipe(dst)
.pipe(dst) returns dst so that you can chain together multiple .pipe() calls together:
a.pipe(b).pipe(c).pipe(d)
which is the same as
a.pipe(b); b.pipe(c); c.pipe(d);
This is very much like what you might do on the command-line to pipe programs together.
a|b|c|d
except in node instead of the shell!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容