The Compression Streams API is for compressing and decompressing streams of data using the gzip or deflate (or deflate-raw) formats.
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') );
To decompress, pipe a compressed stream through the decompression stream.
const decompressedReadableStream = compressedReadableStream.pipeThrough( new DecompressionStream('gzip') );
Part of the Newly interoperable series