decompress.js (922B)
1 /** 2 * @param {Uint8Array} chunk 3 * @param {string} format 4 */ 5 async function decompressData(chunk, format) { 6 const ds = new DecompressionStream(format); 7 const writer = ds.writable.getWriter(); 8 writer.write(chunk); 9 writer.close(); 10 const decompressedChunkList = await Array.fromAsync(ds.readable); 11 const mergedBlob = new Blob(decompressedChunkList); 12 return await mergedBlob.bytes(); 13 } 14 15 /** 16 * @param {Uint8Array} chunk 17 * @param {string} format 18 */ 19 async function decompressDataOrPako(chunk, format) { 20 // Keep using pako for zlib to preserve existing test behavior 21 if (["deflate", "gzip"].includes(format)) { 22 return pako.inflate(chunk); 23 } 24 if (format === "deflate-raw") { 25 return pako.inflateRaw(chunk); 26 } 27 28 // Use DecompressionStream for any newer formats, assuming implementations 29 // always implement decompression if they implement compression. 30 return decompressData(chunk, format); 31 }