mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 19:59:17 +00:00
58 lines
1.5 KiB
HTML
58 lines
1.5 KiB
HTML
<script src="../include.js"></script>
|
|
<script>
|
|
const CHUNK1 = "well,";
|
|
const CHUNK2 = "hello";
|
|
const CHUNK3 = "friends!";
|
|
|
|
asyncTest((done) => {
|
|
const transformStream = new TransformStream({
|
|
transform(chunk, controller) {
|
|
controller.enqueue(
|
|
new TextDecoder("utf-8")
|
|
.decode(chunk)
|
|
.toUpperCase()
|
|
);
|
|
}
|
|
});
|
|
|
|
const stream = new ReadableStream({
|
|
start(controller) {
|
|
pullCount = 0;
|
|
},
|
|
|
|
pull(controller) {
|
|
const textEncoder = new TextEncoder();
|
|
|
|
++pullCount;
|
|
|
|
if (pullCount == 1) {
|
|
controller.enqueue(textEncoder.encode(CHUNK1));
|
|
} else if (pullCount == 2) {
|
|
controller.enqueue(textEncoder.encode(CHUNK2));
|
|
} else if (pullCount == 3) {
|
|
controller.enqueue(textEncoder.encode(CHUNK3));
|
|
} else {
|
|
controller.close();
|
|
}
|
|
},
|
|
|
|
cancel() {},
|
|
});
|
|
|
|
|
|
const reader = transformStream.readable.getReader();
|
|
reader.read().then(function processText({done, value}) {
|
|
if (done)
|
|
return;
|
|
|
|
println(value);
|
|
reader.read().then(processText);
|
|
}).then(() => {
|
|
done();
|
|
});
|
|
|
|
stream.pipeThrough(transformStream);
|
|
|
|
});
|
|
</script>
|