Compression Streams are now supported on all browsers

Browser Support

  • Chrome: 80.
  • Edge: 80.
  • Firefox: 113.
  • Safari: 16.4.

Source

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.

Compress data

The following snippet shows how to compress data:

constreadableStream=awaitfetch('lorem.txt').then(
(response)=>response.body
);
constcompressedReadableStream=readableStream.pipeThrough(
newCompressionStream('gzip')
);

Decompress data

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

constdecompressedReadableStream=compressedReadableStream.pipeThrough(
newDecompressionStream('gzip')
);

Demo

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023年11月02日 UTC.