CompressionStream: CompressionStream() constructor
Compression Streams API
Compression Streams API
The **`CompressionStream()`** constructor creates a new CompressionStream object which compresses a stream of data.
## Syntax
```js-nolint
new CompressionStream(format)
```
### Parameters
- `format`
- : One of the following allowed compression formats:
- `"brotli"`
- : Compresses the stream using the [Brotli](https://www.rfc-editor.org/info/rfc7932/) algorithm.
- `"gzip"`
- : Compresses the stream using the [GZIP](https://www.rfc-editor.org/info/rfc1952/) format.
- `"deflate"`
- : Compresses the stream using the [DEFLATE](https://www.rfc-editor.org/info/rfc1950/) 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](https://www.rfc-editor.org/info/rfc1951/) algorithm without a header and trailing checksum.
- `"zstd"`
- : Compresses the stream using the [ZSTD](https://datatracker.ietf.org/doc/html/rfc8478) algorithm.
### 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
## Browser compatibility
Cite this
"CompressionStream: CompressionStream() constructor". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream/CompressionStream JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy