stream.duplexPair([options])


  • options <Object> 一个传递给两个 Duplex 构造函数的值,用于设置诸如缓冲等选项。
  • 返回:两个 Duplex 实例的 <Array>

实用函数 duplexPair 返回一个包含两个元素的数组,每个元素都是一个相互连接的 Duplex 流:

【The utility function duplexPair returns an Array with two items, each being a Duplex stream connected to the other side:】

const [ sideA, sideB ] = duplexPair(); 

写入一个流的内容可以在另一个流上读取。它提供了类似网络连接的行为,客户端写入的数据可以被服务器读取,反之亦然。

【Whatever is written to one stream is made readable on the other. It provides behavior analogous to a network connection, where the data written by the client becomes readable by the server, and vice-versa.】

双工流是对称的;使用其中任何一个都不会有行为上的差异。

【The Duplex streams are symmetrical; one or the other may be used without any difference in behavior.】