Note: This feature is available in Web Workers.
The CompressionStream()
constructor creates a new CompressionStream
object which compresses a stream of data.
Since May 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Note: This feature is available in Web Workers.
The CompressionStream()
constructor creates a new CompressionStream
object which compresses a stream of data.
new CompressionStream(format)
format
One of the following allowed compression formats:
"gzip"
Compresses the stream using the GZIP format.
"deflate"
Compresses the stream using the DEFLATE algorithm in ZLIB Compressed Data Format. The ZLIB format includes a header with information about the compression method and the uncompressed size of the data, and a trailing checksum for verifying the integrity of the data
"deflate-raw"
Compresses the stream using the DEFLATE algorithm without a header and trailing checksum.
TypeError
Thrown if the format passed to the constructor is not supported.
In this example a stream is compressed using gzip compression.
const compressedReadableStream = inputReadableStream.pipeThrough( new CompressionStream("gzip"), );
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | ||
CompressionStream |
80 | 80 | 113 | 67 | 16.4 | 80 | 113 | 57 | 16.4 | 13.0 | 80 | |
deflate |
80 | 80 | 113 | 67 | 16.4 | 80 | 113 | 57 | 16.4 | 13.0 | 80 | |
deflate-raw |
103 | 103 | 113 | 89 | 16.4 | 103 | 113 | 71 | 16.4 | 20.0 | 103 | |
gzip |
80 | 80 | 113 | 67 | 16.4 | 80 | 113 | 57 | 16.4 | 13.0 | 80 |
© 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/CompressionStream/CompressionStream