CompressionStream: CompressionStream() constructor
The CompressionStream()
constructor creates a new CompressionStream
object which compresses a stream of data.
Syntax
js
new CompressionStream(format)
Parameters
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.
Exceptions
TypeError
-
Thrown if the format passed to the constructor is not supported.
Examples
In this example a stream is compressed using gzip compression.
js
const compressedReadableStream = inputReadableStream.pipeThrough(
new CompressionStream("gzip"),
);
Specifications
Specification |
---|
Compression Streams # dom-compressionstream-compressionstream |
Browser compatibility
BCD tables only load in the browser