import { bytes } from 'node:stream/consumers';
import { Readable } from 'node:stream';
import { Buffer } from 'node:buffer';
const dataBuffer = Buffer.from('hello world from consumers!');
const readable = Readable.from(dataBuffer);
const data = await bytes(readable);
console.log(`from readable: ${data.length}`);
// Prints: from readable: 27
function
stream.consumers.bytes
stream: ReadableStream | AsyncIterable<any, any, any> | ReadableStream<any>
): Promise<NonSharedUint8Array>;
@returns
Fulfills with a Uint8Array containing the full contents of the stream.
Referenced types
interface ReadableStream<R = any>
- ): ReadableStream<T>;