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>
31 lines
922 B
JavaScript
31 lines
922 B
JavaScript
/**
|
|
* @param {Uint8Array} chunk
|
|
* @param {string} format
|
|
*/
|
|
async function decompressData(chunk, format) {
|
|
const ds = new DecompressionStream(format);
|
|
const writer = ds.writable.getWriter();
|
|
writer.write(chunk);
|
|
writer.close();
|
|
const decompressedChunkList = await Array.fromAsync(ds.readable);
|
|
const mergedBlob = new Blob(decompressedChunkList);
|
|
return await mergedBlob.bytes();
|
|
}
|
|
|
|
/**
|
|
* @param {Uint8Array} chunk
|
|
* @param {string} format
|
|
*/
|
|
async function decompressDataOrPako(chunk, format) {
|
|
// Keep using pako for zlib to preserve existing test behavior
|
|
if (["deflate", "gzip"].includes(format)) {
|
|
return pako.inflate(chunk);
|
|
}
|
|
if (format === "deflate-raw") {
|
|
return pako.inflateRaw(chunk);
|
|
}
|
|
|
|
// Use DecompressionStream for any newer formats, assuming implementations
|
|
// always implement decompression if they implement compression.
|
|
return decompressData(chunk, format);
|
|
}
|