CompressionStream: CompressionStream() constructor
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2023.
* Some parts of this feature may have varying levels of support.
Note: This feature is available inWeb Workers.
TheCompressionStream() constructor creates a newCompressionStream object which compresses a stream of data.
In this article
Syntax
new CompressionStream(format)Parameters
formatOne of the following allowed compression formats:
"gzip"Compresses the stream using theGZIP format.
"deflate"Compresses the stream using theDEFLATE 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 theDEFLATE algorithm without a header and trailing checksum.
Exceptions
TypeErrorThrown if the format passed to the constructor is not supported.
Examples
In this example a stream is compressed using gzip compression.
const compressedReadableStream = inputReadableStream.pipeThrough( new CompressionStream("gzip"),);Specifications
| Specification |
|---|
| Compression> # dom-compressionstream-compressionstream> |