mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-25 11:48:06 +00:00
LibWeb: Implement the DecompressionStream interface
This commit is contained in:
parent
638a8aecad
commit
5bcba896c2
Notes:
github-actions[bot]
2024-11-17 22:21:51 +00:00
Author: https://github.com/trflynn89
Commit: 5bcba896c2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2370
9 changed files with 283 additions and 0 deletions
37
Tests/LibWeb/Text/input/Compression/DecompressionStream.html
Normal file
37
Tests/LibWeb/Text/input/Compression/DecompressionStream.html
Normal file
|
@ -0,0 +1,37 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
const data = [
|
||||
// FIXME: Enable this case when our DecompressionStream is functioning with the zlib format.
|
||||
// { format: "deflate", text: "eJwLT83JUchIzcnJV0grykzNSylWBABGEQb1" },
|
||||
{ format: "deflate-raw", text: "C0/NyVHISM3JyVdIK8pMzUspVgQA" },
|
||||
{ format: "gzip", text: "H4sIAAAAAAADAwtPzclRyEjNyclXSCvKTM1LKVYEAHN0w4sTAAAA" },
|
||||
];
|
||||
|
||||
for (const test of data) {
|
||||
const text = Uint8Array.fromBase64(test.text);
|
||||
let stream = new Blob([text]).stream();
|
||||
|
||||
let decompressor = stream.pipeThrough(new DecompressionStream(test.format));
|
||||
let reader = decompressor.getReader();
|
||||
|
||||
let buffer = new ArrayBuffer(256);
|
||||
let offset = 0;
|
||||
|
||||
while (true) {
|
||||
let result = await reader.read();
|
||||
if (result.done) {
|
||||
break;
|
||||
}
|
||||
|
||||
new Uint8Array(buffer).set(result.value, offset);
|
||||
offset += result.value.byteLength;
|
||||
}
|
||||
|
||||
let result = String.fromCharCode.apply(null, new Uint8Array(buffer, 0, offset));
|
||||
println(`format=${test.format}: ${result}`);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue