mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibWeb: Use ArrayBufferView for ReadableStreamBYOBReader
Which means that we now have support for DataViews. Using the ArrayBufferView class also seems to make this read a whole bunch nicer as well.
This commit is contained in:
parent
eab20129b9
commit
673329e1bd
7 changed files with 41 additions and 37 deletions
|
@ -1,6 +1,6 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
async function testByobRead(type) {
|
||||
const array = ['This is some data to be read! 🦬'];
|
||||
let blob = new Blob(array);
|
||||
|
||||
|
@ -11,15 +11,14 @@
|
|||
let bytesReceived = 0;
|
||||
let offset = 0;
|
||||
|
||||
println(`About to read! ${reader}`);
|
||||
println(`About to read into ${type.prototype.constructor.name} with ${reader}`);
|
||||
|
||||
while (true) {
|
||||
let result = await reader.read(new Uint8Array(buffer, offset, buffer.byteLength - offset));
|
||||
let result = await reader.read(new type(buffer, offset, buffer.byteLength - offset));
|
||||
|
||||
if (result.done) {
|
||||
println(`Total bytes: ${bytesReceived}`);
|
||||
println(`'${new TextDecoder().decode(result.value.buffer.slice(0, bytesReceived))}'`);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,5 +26,11 @@
|
|||
offset += result.value.byteLength;
|
||||
bytesReceived += result.value.byteLength;
|
||||
}
|
||||
}
|
||||
|
||||
asyncTest(async done => {
|
||||
await testByobRead(Uint8Array);
|
||||
await testByobRead(DataView);
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue