← Back to release summary

ReadableStreamBYOBReader Min Option

Category
Miscellaneous
Type
Chromium catches up
Status
Proposed (Chrome Proposed)
Intent stage
None

Summary

This feature introduces a min option to the existing ReadableStreamBYOBReader.read(view) API. The API already accepts a ArrayBufferView into which data is read, but currently does not guarantee how many elements will be written before the read resolves. The min option is an additive, opt-in enhancement - it does not affect existing behavior for applications that don’t use it. By specifying a min value, developers can require that the stream wait until at least that many elements are available before resolving the read. This improves upon the current behavior, where reads may resolve with fewer elements than the view can hold.

Motivation

The ReadableStreamBYOBReader.read(view) method allows developers to supply a buffer view into which stream data is read. However, the current behavior does not guarantee how many elements will be written into the buffer. The stream may resolve the read with fewer elements than the view can accommodate. This behavior can be inefficient or problematic in performance-sensitive applications where consumers often require a minimum number of elements before they can proceed with decoding, parsing, or other processing logic. Introducing a { min } option to read(view, { min }) allows developers to explicitly specify the minimum number of elements that must be available before the read resolves.

Standards & signals

View on chromestatus.com