Bun

Node.js module

stream/consumers

The 'node:stream/consumers' submodule offers helper functions that consume Readable streams into other forms, such as blob, arrayBuffer, text, or json.

It simplifies common stream-to-data conversions without manual event handling.

  • function arrayBuffer(
    stream: ReadableStream<any> | ReadableStream | AsyncIterable<any, any, any>
    ): Promise<ArrayBuffer>;
    @returns

    Fulfills with an ArrayBuffer containing the full contents of the stream.

  • function blob(
    stream: ReadableStream<any> | ReadableStream | AsyncIterable<any, any, any>
    ): Promise<Blob>;
    @returns

    Fulfills with a Blob containing the full contents of the stream.

  • function buffer(
    stream: ReadableStream<any> | ReadableStream | AsyncIterable<any, any, any>
    ): Promise<Buffer<ArrayBufferLike>>;
    @returns

    Fulfills with a Buffer containing the full contents of the stream.

  • function json(
    stream: ReadableStream<any> | ReadableStream | AsyncIterable<any, any, any>
    ): Promise<unknown>;
    @returns

    Fulfills with the contents of the stream parsed as a UTF-8 encoded string that is then passed through JSON.parse().

  • function text(
    stream: ReadableStream<any> | ReadableStream | AsyncIterable<any, any, any>
    ): Promise<string>;
    @returns

    Fulfills with the contents of the stream parsed as a UTF-8 encoded string.