2024-10-18:
The plan of record for passable immutable binary data is an immutable ArrayBuffer per our proposal to TC39.
2022-10-18:
Our current best solution for carrying bytes is a Uint8Array, which we use pervasively for hardened streams. This is one of the reasons that we treat Typed Arrays like Map for the purposes of hardening. The content is mutable but the API surface is tamper-proof. However, the content is readable and writable by both the sender and receiver over time, so like a Map, TypedArrays are not passable. That makes them a poor foundation for remote streams in an ocap discipline.
I propose that we need an analogous solution to the CopyMap and MapStore for transmission of immutable byte strings, tentatively CopyBytes and BytesStore, which would be passable and provide a firmer foundation for streams (async iterators of byte strings). CopyBytes should mesh well with TypedArrays, particularly Uint8Array and ArrayBuffer. To that end, it may be necessary for them to be Proxies, such that uint8Array.set(copyBytes) is sensible. Constructing an immutable copy of the content of an array-like should be possible, like copyBytes(uint8Array) or makeCopyBytes([0, 1, 2, …, 127]). CopyBytes would be backed by a TypedArray but would attenuate mutability. Slicing CopyBytes should be trivial. As with glyph strings, ropes are a possible optimization in the fullness of time.
As a critical optimization, we often use ring buffers for byte streams. We could conceivably also support another type for revocable copy bytes, that would permit a stream to reclaim the underlying byte range when the consumer signals it’s ready for another subrange.
2024-10-18:
The plan of record for passable immutable binary data is an immutable
ArrayBufferper our proposal to TC39.2022-10-18:
Our current best solution for carrying bytes is a Uint8Array, which we use pervasively for hardened streams. This is one of the reasons that we treat Typed Arrays like Map for the purposes of hardening. The content is mutable but the API surface is tamper-proof. However, the content is readable and writable by both the sender and receiver over time, so like a Map, TypedArrays are not passable. That makes them a poor foundation for remote streams in an ocap discipline.
I propose that we need an analogous solution to the
CopyMapandMapStorefor transmission of immutable byte strings, tentativelyCopyBytesandBytesStore, which would be passable and provide a firmer foundation for streams (async iterators of byte strings).CopyBytesshould mesh well with TypedArrays, particularly Uint8Array and ArrayBuffer. To that end, it may be necessary for them to be Proxies, such thatuint8Array.set(copyBytes)is sensible. Constructing an immutable copy of the content of an array-like should be possible, likecopyBytes(uint8Array)ormakeCopyBytes([0, 1, 2, …, 127]).CopyByteswould be backed by a TypedArray but would attenuate mutability. SlicingCopyBytesshould be trivial. As with glyph strings, ropes are a possible optimization in the fullness of time.As a critical optimization, we often use ring buffers for byte streams. We could conceivably also support another type for revocable copy bytes, that would permit a stream to reclaim the underlying byte range when the consumer signals it’s ready for another subrange.