Open sandersdan opened 4 years ago
IIUC, this still entails copying. When you construct the blob from an ArrayBuffer, the spec says you copy those bytes. When you get an ArrayBuffer via arrayBuffer(), I think this is again a copy (spec is less clear to me here).
There is also the opposite case, where we decode a VideoFrame and then want to expose the contents. We can do so as a Blob without copying.
There is a proposal to be able to mmap Blobs in WASM, if that lands it could be very helpful.
https://github.com/Jack-Works/proposal-readonly-arraybuffer https://github.com/Jack-Works/proposal-arraybuffer-fixed-view
are two recent proposals in ES that would be helpful for this.
triage note: marking 'extension' as proposals above involve new methods/attributes without breaking.
Related: It would be really nice from a developer experience standpoint if these APIs also consumed File
and Blob
, as that’s what you get from an <input type="file">
element.
Workaround for now is to do
const decoder = new ImageDecoder({
type: file.type,
data: new Response(file).body
});
Due to the lack of read-only ArrayBuffers, extra copying may be necessary to make some WebCodecs APIs safe.
Blobs however can be read-only. We should investigate whether supporting Blobs in some APIs would be beneficial.