PR-URL: https://github.com/nodejs/node/pull/62107 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mattias Buelens <mattias@buelens.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
// META: global=window,worker,shadowrealm
|
|
// 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}`);
|
|
}
|
|
}
|