-
Notifications
You must be signed in to change notification settings - Fork 167
Description
(based on @yutakahirano's analysis)
An identity transform can be designed to pass the ArrayBufferView
s (after detaching) written to the writable side as-is to the readable side. This is good since no copy happens.
We have three choices in implementing this:
- (a) on
.write()
, the transform takes ownership of theArrayBufferView
permanently - (b) on
.write()
, the transform takes ownership but returns it later (notify ownership release by fulfilling the promise returned by.write()
) - (c) on
.write()
, the transform reads out all the bytes from theArrayBufferView
. It never takes ownership.
(a) allows the transform to pass the ArrayBufferView
as-is (after detaching) to the consumer through ReadableStream
without ack capability (non-BYOB), but disallows the producer to reuse the buffer.
(b) allows the producer to reuse the buffer, but if the readable side is ReadableStream
without ack capability (non-BYOB), there's no way to get the buffer returned by the consumer, so, we need to copy data inside the transform. To eliminate copy, we need ReadableStream
with ack.
When BYOB reading is used, we anyway need to copy bytes.