ByteLengthQueuingStrategy: 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.

ByteLengthQueuingStrategy() コンストラクターは、ByteLengthQueuingStrategy オブジェクトのインスタンスを作成して返します。

構文

js
new ByteLengthQueuingStrategy(highWaterMark)

引数

以下のプロパティを持つオブジェクトです。

highWaterMark

背圧が適用される前に内部キューに格納することができるバイト数の合計です。

CountQueuingStrategy() では highWaterMark 引数に単純な塊の数を指定しますが、 ByteLengthQueuingStrategy() では、 highWaterMark 引数はバイト数を指定します。具体的には、チャンクのストリームが指定された場合に、背圧が適用される前に内部キューに何バイト分のチャンクを格納することができるか(チャンクの数ではありません)を指定します。

返値

ByteLengthQueuingStrategy オブジェクトのインスタンスです。

例外

なし。

js
const queuingStrategy = new ByteLengthQueuingStrategy({
  highWaterMark: 1 * 1024,
});

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

const size = queuingStrategy.size(chunk);

仕様書

Specification
Streams Standard
# blqs-constructor

ブラウザーの互換性

BCD tables only load in the browser

関連情報