node.js - Node JS : What's the difference between a Duplex stream and a Transform stream?

标签 node.js stream

Stream docs声明 Duplex Streams “是实现 Readable 和 Writable 接口(interface)的流”和 Transform Streams “是以某种方式从输入计算输出的双工流。”不幸的是,文档没有描述 Transform 流在 Duplex 流之外提供什么。

这两者有什么不同吗?您什么时候会使用其中一个?

最佳答案

双工流可以被认为是一个可读流和一个可写流。两者都是独立的,并且每个都有单独的内部缓冲区。读取和写入事件独立发生。

                             Duplex Stream
                          ------------------|
                    Read  <-----               External Source
            You           ------------------|   
                    Write ----->               External Sink
                          ------------------|
            You don't get what you write. It is sent to another source.

Transform 流是一种双工,其中读取和写入以因果方式发生。双工流的端点通过某种变换链接。读需要写。

                                 Transform Stream
                           --------------|--------------
            You     Write  ---->                   ---->  Read  You
                           --------------|--------------
            You write something, it is transformed, then you read something.

关于node.js - Node JS : What's the difference between a Duplex stream and a Transform stream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18335499/

相关文章:

javascript - Sublime Text 3 Linter 问题

node.js - 有人在 Elastic Beanstalk 上使用过 Workbox 吗?未检测到

javascript - Angular 应用程序不会处理 MongoDB 对象

node.js - 在 Meteor 中,如何从集合查找游标中获取 Node 读取流?

c# - 如何在新选项卡或窗口中打开 PDF 文件而不是下载它(使用 asp.net)?

javascript - 从 View 中访问本地人的 sails

javascript - 如何使用实现接口(interface)制作 Typescript 枚举

c# - 计算上传传输速度问题

java - 使用 RTP 在 JMF 中实现播放器

node.js - 对这个流可读语法有点困惑