readable.compose(stream[, options])
稳定性: 1 - 实验性的
¥Stability: 1 - Experimental
-
stream
<Stream> | <Iterable> | <AsyncIterable> | <Function> -
options
<Object>-
signal
<AbortSignal> 如果信号中止,允许销毁流。¥
signal
<AbortSignal> allows destroying the stream if the signal is aborted.
-
-
返回:<Duplex> 是与流
stream
组成的流。¥Returns: <Duplex> a stream composed with the stream
stream
.
import { Readable } from 'node:stream';
async function* splitToWords(source) {
for await (const chunk of source) {
const words = String(chunk).split(' ');
for (const word of words) {
yield word;
}
}
}
const wordsStream = Readable.from(['this is', 'compose as operator']).compose(splitToWords);
const words = await wordsStream.toArray();
console.log(words); // prints ['this', 'is', 'compose', 'as', 'operator']
有关详细信息,请参阅 stream.compose
。
¥See stream.compose
for more information.