ByteLengthQueuingStrategy

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上使用。自 ⁨2019 年 1 月⁩起,它已在所有瀏覽器中可用。

注意:此功能在 Web Workers 中可用。

ByteLengthQueuingStrategy 介面屬於 Streams API,它提供了一種內建的位元組長度排隊策略,可用於構建流時使用。

建構函式

ByteLengthQueuingStrategy()

建立一個新的 ByteLengthQueuingStrategy 物件例項。

例項屬性

ByteLengthQueuingStrategy.highWaterMark 只讀

在應用 背壓 之前,內部佇列中可以包含的總位元組數。

例項方法

ByteLengthQueuingStrategy.size()

返回給定塊的 byteLength 屬性。

示例

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

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

const size = queueingStrategy.size(chunk);

規範

規範
Streams
# blqs-class

瀏覽器相容性

另見