Files
sousa-gecko/testing/web-platform/tests/compression/decompression-split-chunk.any.js
T
Anne van Kesteren 47a27e9af8 Bug 2038779 [wpt PR 59794] - Remove ShadowRealm test coverage, a=testonly
Automatic update from web-platform-tests
Remove ShadowRealm test coverage

This intentionally does not make infrastructure or documentation changes, but without implementer support all the ShadowRealm tests add significant noise. Once there is implementer support this can be reverted.

--

wpt-commits: e4a4672e9e607fc2b28e7173b83ce4e38ef53071
wpt-pr: 59794
2026-05-13 04:24:16 +00:00

39 lines
1.2 KiB
JavaScript

// META: global=window,worker
// META: script=resources/decompression-input.js
'use strict';
async function decompressArrayBuffer(input, format, chunkSize) {
const ds = new DecompressionStream(format);
const reader = ds.readable.getReader();
const writer = ds.writable.getWriter();
for (let beginning = 0; beginning < input.length; beginning += chunkSize) {
writer.write(input.slice(beginning, beginning + chunkSize));
}
writer.close();
const out = [];
let totalSize = 0;
while (true) {
const { value, done } = await reader.read();
if (done) break;
out.push(value);
totalSize += value.byteLength;
}
const concatenated = new Uint8Array(totalSize);
let offset = 0;
for (const array of out) {
concatenated.set(array, offset);
offset += array.byteLength;
}
return concatenated;
}
for (const [format, bytes] of compressedBytes) {
for (let chunkSize = 1; chunkSize < 16; ++chunkSize) {
promise_test(async t => {
const decompressedData = await decompressArrayBuffer(bytes, format, chunkSize);
assert_array_equals(decompressedData, expectedChunkValue, "value should match");
}, `decompressing splitted chunk into pieces of size ${chunkSize} should work in ${format}`);
}
}