Decompress the output and verify it matches the original:
// Two-function wrapper — write once, use everywhere async function compress(input, format = 'gzip') { const stream = new Blob([input]) .stream() .pipeThrough(new CompressionStream(format)); return new Uint8Array(await new Response(stream).arrayBuffer()); } async function decompress(input, format = 'gzip') { const stream = new Blob([input]) .stream() .pipeThrough(new DecompressionStream(format)); return new Response(stream).text(); } // Usage const compressed = await compress(jsonString); const restored = await decompress(compressed);