Converts a classic Readable stream (or duck-typed equivalent) into a stream/iter async iterable source that can be passed to from(), pull(), text(), etc.
If the object implements the toAsyncStreamable protocol (as stream.Readable does), that protocol is used. Otherwise, the function duck-types on read() and on() (EventEmitter) and wraps the stream with a batched async iterator.
The result is cached per instance -- calling fromReadable() twice with the same stream returns the same iterable.
For object-mode or encoded Readable streams, chunks are automatically normalized to Uint8Array.
import { Readable } from 'node:stream';
import { fromReadable, text } from 'node:stream/iter';
const readable = new Readable({
read() { this.push('hello world'); this.push(null); },
});
const result = await text(fromReadable(readable));
console.log(result); // 'hello world'