Function detectReadableStreamType

detects the type of a ReadableStream.

Note

note that the original stream is partially consumed, and you will not be able to use it any longer. instead, you will have to use the new stream returned by this function for consumption.

Note

note that it is possible for a stream to contain all sorts of different types in each of its chunk, but we make our prediction based on only the first chunk's type.

the implementation works as follows:

  • create 2 clones of the original-stream via the tee method
  • read the first-stream-clone's first chunk, and guess the type based on it
  • cancel the original-stream and the first-stream-clone
  • return the untouched second-stream-clone and the guessed type in an Object wrapper
  • Type Parameters

    • T
    • K extends
          | "string"
          | "number"
          | "bigint"
          | "boolean"
          | "symbol"
          | "undefined"
          | "object"
          | "function"
          | "uint8array"
          | "arraybuffer"
          | "array"
          | "null"

    Parameters

    • stream: ReadableStream<T>

    Returns Promise<{ kind: K; stream: ReadableStream<T> }>