Function concatReadableStreams

  • Concatenates multiple ReadableStreams into a single ordered ReadableStream.

    Cancelling the resulting stream will cancel all the input streams.

    Type Parameters

    • T

      The type of the chunks in the streams.

    Parameters

    • Rest...streams: ReadableStream<T>[]

      An iterable of ReadableStreams to concat.

    Returns ReadableStream<T>

    A ReadableStream that will emit the concatenated chunks.

    import { concatReadableStreams } from "@std/streams/concat-readable-streams";
    import { assertEquals } from "@std/assert";

    const stream1 = ReadableStream.from([1, 2, 3]);
    const stream2 = ReadableStream.from([4, 5, 6]);
    const stream3 = ReadableStream.from([7, 8, 9]);

    assertEquals(
    await Array.fromAsync(concatReadableStreams(stream1, stream2, stream3)),
    [1, 2, 3, 4, 5, 6, 7, 8, 9],
    );