Skip to main content
Version: 3.28.0

ReadableStream.getReader()

The getReader() method of the ReadableStream interface creates a reader and locks the stream to it. While the stream is locked, no other reader can be acquired until this one is released.

Syntax

getReader()
getReader(options)

Parameters

  • options optional

    • : An object containing the following properties:

      • mode optional

        • : A property that specifies the type of reader to create. Values can be:

          • "byob", which results in a ReadableStreamBYOBReader being created that can read readable byte streams (streams that support zero-copy transfer from an underlying byte source to the reader when internal stream buffers are empty).
          • undefined (or not specified at all — this is the default), which results in a ReadableStreamDefaultReader being created that can read individual chunks from a stream.

Return value

A ReadableStreamDefaultReader or ReadableStreamBYOBReader object instance, depending on the mode value.

Exceptions

  • RangeError
    • : Thrown if the provided mode value is not "byob" or undefined.
  • TypeError
    • : Thrown if the stream you are trying to create a reader for is already locked, or not a ReadableStream.