toReadable(source[, options])
稳定性: 1 - 实验性
source<AsyncIterable>AsyncIterable<Uint8Array[]>来源,例如pull()或from()的返回值。options<Object>highWaterMark<number> 在应用反压之前的内部缓冲区大小(以字节为单位)。默认值:65536(64 KB)。signal<AbortSignal> 可选信号以中止可读流。
- 返回:<stream.Readable>
从 AsyncIterable<Uint8Array[]> 创建一个字节模式的 stream.Readable(流/迭代 API 使用的本地批处理格式)。在生成的批处理中,每个 Uint8Array 都会作为单独的块推送到可读对象中。
🌐 Creates a byte-mode stream.Readable from an AsyncIterable<Uint8Array[]>
(the native batch format used by the stream/iter API). Each Uint8Array in a
yielded batch is pushed as a separate chunk into the Readable.
import { createWriteStream } from 'node:fs';
import { from, pull, toReadable } from 'node:stream/iter';
import { compressGzip } from 'node:zlib/iter';
const source = pull(from('hello world'), compressGzip());
const readable = toReadable(source);
readable.pipe(createWriteStream('output.gz'));const { createWriteStream } = require('node:fs');
const { from, pull, toReadable } = require('node:stream/iter');
const { compressGzip } = require('node:zlib/iter');
const source = pull(from('hello world'), compressGzip());
const readable = toReadable(source);
readable.pipe(createWriteStream('output.gz'));