Compression Streams are now supported on all browsers

The Compression Streams API is for compressing and decompressing streams of data using the gzip or deflate (or deflate-raw) formats.

Using the built-in compression of the Compression Streams API, JavaScript applications do not need to include a compression library, making the download size of the application smaller. This useful API is now supported across all browsers.

Compressing data

The following snippet shows how to compress data:

const readableStream = await fetch('lorem.txt').then(
  (response) => response.body
);
const compressedReadableStream = readableStream.pipeThrough(
  new CompressionStream('gzip')
);

Decompressing data

To decompress, pipe a compressed stream through the decompression stream.

const decompressedReadableStream = compressedReadableStream.pipeThrough(
  new DecompressionStream('gzip')
);

Browser compatibility

Browser Support

  • 80
  • 80
  • 113
  • 16.4

Source

Demo

Part of the Newly interoperable series