ReadableByteStreamController: byobRequest プロパティ

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

byobRequestReadableByteStreamController インターフェイスの読み取り専用プロパティで、現在の BYOB リクエストを返します。保留中のリクエストがない場合は null を返します。

基盤となるバイトソースはこのプロパティを調べ、存在する場合はそれを使用してストリームにデータを書き込む必要があります(ReadableByteStreamController.enqueue()を使用するのではなく)。 こうすることで、コンシューマーへのデータの効率的なゼロバイト移譲が実現します。

ReadableStreamBYOBRequest オブジェクトのインスタンス、または null

読み取り可能なバイトストリームの使用 > 読み取り可能なソケットプッシュバイトストリームの作成の例では、 byobRequest を使用して(データが存在する場合は)データを移譲するか、 ReadableByteStreamController.enqueue() を使用してストリーム内部のキューにデータをコピーする方法を示しています。

関連するコードを下記に示します。 byobRequest が存在すれば、 controller.byobRequest.view にデータが読み込まれ、 ReadableStreamBYOBRequest.respond() が呼び出されて、移譲可能なデータ量を指示します。

js
if (controller.byobRequest) {
  const v = controller.byobRequest.view;
  bytesRead = socket.readInto(v.buffer, v.byteOffset, v.byteLength);
  if (bytesRead === 0) {
    controller.close();
  }
  controller.byobRequest.respond(bytesRead);
} else {
  // Write to data using enqueue().
}

仕様書

Specification
Streams
# ref-for-rbs-controller-byob-request②

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
byobRequest

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

関連情報