stream.Duplex.from(src)
src
<Stream> | <Blob> | <ArrayBuffer> | <string> | <Iterable> | <AsyncIterable> | <AsyncGeneratorFunction> | <AsyncFunction> | <Promise> | <Object> | <ReadableStream> | <WritableStream>
用于创建双工流的实用方法。
¥A utility method for creating duplex streams.
-
Stream
将可写流转换为可写的Duplex
,将可读流转换为Duplex
。¥
Stream
converts writable stream into writableDuplex
and readable stream toDuplex
. -
Blob
转换为可读的Duplex
。¥
Blob
converts into readableDuplex
. -
string
转换为可读的Duplex
。¥
string
converts into readableDuplex
. -
ArrayBuffer
转换为可读的Duplex
。¥
ArrayBuffer
converts into readableDuplex
. -
AsyncIterable
转换为可读的Duplex
。无法生成null
。¥
AsyncIterable
converts into a readableDuplex
. Cannot yieldnull
. -
AsyncGeneratorFunction
转换为可读/可写的转换Duplex
。必须将源AsyncIterable
作为第一个参数。无法生成null
。¥
AsyncGeneratorFunction
converts into a readable/writable transformDuplex
. Must take a sourceAsyncIterable
as first parameter. Cannot yieldnull
. -
AsyncFunction
转换为可写的Duplex
。必须返回null
或undefined
¥
AsyncFunction
converts into a writableDuplex
. Must return eithernull
orundefined
-
Object ({ writable, readable })
将readable
和writable
转换为Stream
,然后将它们组合成Duplex
,其中Duplex
将写入writable
并从readable
读取。¥
Object ({ writable, readable })
convertsreadable
andwritable
intoStream
and then combines them intoDuplex
where theDuplex
will write to thewritable
and read from thereadable
. -
Promise
转换为可读的Duplex
。忽略值null
。¥
Promise
converts into readableDuplex
. Valuenull
is ignored. -
ReadableStream
转换为可读的Duplex
。¥
ReadableStream
converts into readableDuplex
. -
WritableStream
转换为可写的Duplex
。¥
WritableStream
converts into writableDuplex
. -
¥Returns: <stream.Duplex>
如果将包含 promise 的 Iterable
对象作为参数传递,可能会导致未处理的拒绝。
¥If an Iterable
object containing promises is passed as an argument,
it might result in unhandled rejection.
const { Duplex } = require('node:stream');
Duplex.from([
new Promise((resolve) => setTimeout(resolve('1'), 1500)),
new Promise((_, reject) => setTimeout(reject(new Error('2')), 1000)), // Unhandled rejection
]);