WritableStreamDefaultWriter: desiredSize property

Baseline
Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2022.

Note: This feature is available in Web Workers.

The desiredSize read-only property of the WritableStreamDefaultWriter interface returns the desired size required to fill the stream's internal queue.

Value

A number, or null.

The number can be negative if the queue is over-full. When a custom queuing strategy is used, its chunk sizes can cause the number to have a fractional component. The value is null if the stream is erroring or errored, and 0 if it is closed.

Exceptions

TypeError

The writer's lock is released.

Examples

js
const writableStream = new WritableStream(
  {
    write(chunk) {
      // …
    },
    close() {
      // …
    },
    abort(err) {
      // …
    },
  },
  queuingStrategy,
);

// …

const writer = writableStream.getWriter();

// …

// return stream's desired size
const size = writer.desiredSize;

Specifications

Specification
Streams
# ref-for-default-writer-desired-size⑥

Browser compatibility