> Does the browser call this callback?
Yes. `stream.getReader().read()` (or C++ equivalent of it) will call the callback. You can take look at [Chromium Fetch implementation](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/fetch/readable_stream_bytes_consumer.cc;l=114-115;drc=35406c8d4b7301ede262aeedfc6a63e5e3cf555d) to see how it works there:
> How does the web author generate these `bytes`?
If the data is string then one can use TextEncoderStream to do the work:
```js
let stream = new ReadableStream({
pull(controller) {
controller.enqueue("hello");
}
});
let encodedStream = stream.pipeThrough(new TextEncoderStream()); // encodes each data chunk on demand
let reader = encodedStream.getReader();
console.log(await reader.read()); // { done: false, value: Uint8Array([104, 101, 108, 108, 111])
```
If the data is binary, then you already have it.
--
Reply to this email directly or view it on GitHub:
https://github.com/w3c/clipboard-apis/issues/212#issuecomment-1939435788
You are receiving this because you are subscribed to this thread.
Message ID: <w3c/clipboard-apis/issues/212/1939435788@github.com>