CompressionStream
Compress text natively — no pako, no imports
Input text
Presets:
Compression result
Original — bytes
Characters
UTF-8 bytes
Compressed — bytes
Compressed bytes
Savings
Size ratio
0% (nothing)100% (original)
First 64 bytes (hex preview)
Round-trip decompression

Decompress the output and verify it matches the original:

The code — copy and use
// 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);