W3cubDocs

/Web APIs

ReadableByteStreamController: desiredSize property

The desiredSize read-only property of the ReadableByteStreamController interface returns the number of bytes required to fill the stream's internal queue to its "desired size".

The value is used by the stream to indicate a preferred flow rate to the underlying source. Sources that support throttling or pausing their inflow of data (not all do!) should control the inflow such that desiredSize of the stream buffer is kept positive and as close to zero as possible.

The desiredSize is used to apply backpressure from downstream consumers.

Value

An integer. Note that this can be negative if the queue is over-full.

The value will be null if the stream has errored and 0 if it is closed.

Examples

The A readable stream with an underlying push source and backpressure support example in the spec provides a good example of using desiredSize to manually detect when the stream is full and apply backpressure.

While the example uses a default source, the concepts are exactly the same as for readable byte sources.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
desiredSize 89 89 102 No 75 No 89 89 102 63 No 15.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ReadableByteStreamController/desiredSize