mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 10:37:17 +02:00
LibWeb: Implement ReadableStreamBYOBReader::read
Similiarly to the underlying AO's, currently only TypedArrays are supported.
This commit is contained in:
committed by
Andreas Kling
parent
dcb7bb4a92
commit
1daded768d
Notes:
sideshowbarker
2024-07-16 22:54:10 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/1daded768d Pull-request: https://github.com/SerenityOS/serenity/pull/21983
@@ -0,0 +1,31 @@
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
const array = ['This is some data to be read! 🦬'];
|
||||
let blob = new Blob(array);
|
||||
|
||||
const stream = blob.stream();
|
||||
const reader = stream.getReader({ mode: "byob" });
|
||||
|
||||
let buffer = new ArrayBuffer(200);
|
||||
let bytesReceived = 0;
|
||||
let offset = 0;
|
||||
|
||||
println(`About to read! ${reader}`);
|
||||
|
||||
while (true) {
|
||||
let result = await reader.read(new Uint8Array(buffer, offset, buffer.byteLength - offset));
|
||||
|
||||
if (result.done) {
|
||||
println(`Total bytes: ${bytesReceived}`);
|
||||
println(`'${new TextDecoder().decode(result.value.buffer.slice(0, bytesReceived))}'`);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
buffer = result.value.buffer;
|
||||
offset += result.value.byteLength;
|
||||
bytesReceived += result.value.byteLength;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user