stream.duplexPair([options])


  • options <Object> 传递给两个 Duplex 构造函数的值,用于设置缓冲等选项。

    ¥options <Object> A value to pass to both Duplex constructors, to set options such as buffering.

  • 返回:两个 Duplex 实例中的 <Array>

    ¥Returns: <Array> of two Duplex instances.

实用函数 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.

Duplex 流是对称的;可以使用其中一个,行为没有任何区别。

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