CompressionStream.CompressionStream()

The CompressionStream() constructor creates a new CompressionStream object which compresses a stream of data.

Syntax

let CompressionStream = new CompressionStream(format);

Parameters

format
One of the following allowed compression formats:
  • "gzip"
  • "deflate"

Exceptions

TypeError
Thrown 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 Status Comment
Compression Streams
The definition of 'CompressionStream()' in that specification.
Draft Initial definition.

Browser compatibility

BCD tables only load in the browser