ByteLengthQueuingStrategy

Baseline 2022

Newly available

Since June 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Streams APIByteLengthQueuingStrategy 接口提供了一个队列策略,该队列策略提供了内置的字节长度并且可以在构造流的时候使用。

构造函数

ByteLengthQueuingStrategy()

创建一个新的 ByteLengthQueuingStrategy 对象实例。

实例属性

ByteLengthQueuingStrategy.highWaterMark 只读

在应用背压之前,内部队列可以包含的字节总数。

实例方法

ByteLengthQueuingStrategy.size()

返回给定分块的 byteLength 属性。

示例

js
const queueingStrategy = new ByteLengthQueuingStrategy({ highWaterMark: 1 });

const readableStream = new ReadableStream(
  {
    start(controller) {
      // …
    },
    pull(controller) {
      // …
    },
    cancel(err) {
      console.log("stream error:", err);
    },
  },
  queueingStrategy,
);

const size = queueingStrategy.size(chunk);

规范

Specification
Streams Standard
# blqs-class

浏览器兼容性

BCD tables only load in the browser

参见