W3cubDocs

/Web APIs

Compression Streams API

The Compression Streams API provides a JavaScript API for compressing and decompressing streams of data using the gzip or deflate formats.

Built in compression means that JavaScript applications will not need to include a compression library, which makes the download size of the application smaller.

Interfaces

CompressionStream

Compresses a stream of data.

DecompressionStream

Decompresses a stream of data.

Examples

In this example a stream is compressed using gzip compression.

js

const compressedReadableStream = inputReadableStream.pipeThrough(
  new CompressionStream("gzip"),
);

In the following example a function decompresses a blob using gzip.

js

async function DecompressBlob(blob) {
  const ds = new DecompressionStream("gzip");
  const decompressedStream = blob.stream().pipeThrough(ds);
  return await new Response(decompressedStream).blob();
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
CompressionStream 80 80 113 No 67 16.4 80 80 113 57 16.4 13.0
Compression_Streams_API 80 80 113 No 67 16.4 80 80 113 57 16.4 13.0
readable 80 80 113 No 67 16.4 80 80 113 57 16.4 13.0
writable 80 80 113 No 67 16.4 80 80 113 57 16.4 13.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API