← Back to release summary

SerialPort BYOB reader support

Category
Device
Type
New or changed feature
Status
Enabled by default (Chrome 106)
Intent stage
Shipped

Summary

Updates the underlying data source for the ReadableStream provided by a SerialPort to be a readable byte stream. This change is backwards-compatible with existing code that calls port.readable.getReader() with no parameters. Developers can detect support for BYOB readers by calling getReader({ mode: 'byob' }) as older implementations will throw a TypeError when the new parameter is passed. BYOB (or, "bring your own buffer") readers allow the developer to specify the buffer into which data is read instead of the stream allocating a new buffer for each chunk. In addition to potentially reducing memory pressure this allows the developer to control how much data is received as the stream cannot return more than there is space for in the provided buffer. The ability to read a particular amount of data from a port makes this API more familiar to developers used to programming against the Windows and POSIX APIs for serial devices, which operate on this same "bring your own buffer" principle.

Motivation

BYOB readers allow developers to specify the buffer into which data is read instead of the stream allocating a buffer for each chunk. In addition to the potential reduction in memory pressure this allows script to control how much data is received in a chunk as the stream cannot return more than there is space for in the provided buffer. The ability to read a particular amount of data from a port has been a frequently requested feature by developers used to programming against the Windows and POSIX APIs for serial devices, which operate on this same "bring your own buffer" principle. The current API, in contrast, requires developers to code defensively against extra unwanted data instead of reading only what they are ready to process.

Standards & signals

Samples: https://googlechromelabs.github.io/serial-terminal

View on chromestatus.com