Skip to main content
Version: 3.27.2

ReadableStreamDefaultReader.read()

The read() method of the ReadableStreamDefaultReader interface returns a Promise providing access to the next chunk in the stream's internal queue.

Syntax

read()

Parameters

None.

Return value

A Promise, which fulfills/rejects with a result depending on the state of the stream. The different possibilities are as follows:

  • If a chunk is available, the promise will be fulfilled with an object of the form { value: theChunk, done: false }.
  • If the stream becomes closed, the promise will be fulfilled with an object of the form { value: undefined, done: true }.
  • If the stream becomes errored, the promise will be rejected with the relevant error.

Exceptions

  • TypeError
    • : The source object is not a ReadableStreamDefaultReader, the stream has no owner, or ReadableStreamDefaultReader.releaseLock() is called (when there's a pending read request).