大网数据广告活动
Web 标准与前端开发

ReadableByteStreamController: desiredSize property

· 52CE 我爱测

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".

Streams

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

A number, or null.

The number can be negative if the queue is over-full. Although the queue size is measured in bytes, a fractional high water mark can cause the number to have a fractional component. The value is 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

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。