ladybird/Tests/LibWeb/Text/input/Compression/DecompressionStream.html
Valtteri Koskivuori 135daeb8bb LibCompress: Don't assume zlib header is available right away
Instead of checking the header in ZlibDecompressor::create(), we now
check it in read_some() when it is called for the first time. This
resolves a FIXME in the new DecompressionStream implementation.
2024-11-18 19:55:46 -05:00

36 lines
1.2 KiB
HTML

<script src="../include.js"></script>
<script>
asyncTest(async done => {
const data = [
{ 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>