# Compression streams

> How Elide supports CompressionStream and DecompressionStream: gzip, deflate and deflate-raw per the standard, plus Brotli and Zstandard formats.

`CompressionStream` and `DecompressionStream` are globals from the
[Compression Streams Standard](https://compression.spec.whatwg.org/). They take a format: `gzip`, `deflate`
(zlib-wrapped), `deflate-raw`, `brotli`, or `zstd`.

## Example

```js
// compression.mjs
const input = new Blob(["elide ".repeat(100)]);
const compressed = await new Response(input.stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
console.log(input.size, "->", compressed.byteLength);

const restored = new Blob([compressed]).stream().pipeThrough(new DecompressionStream("gzip"));
console.log((await new Response(restored).text()).length);
```

`elide run compression.mjs` prints:

```text
600 -> 35
600
```

## Differences from browsers

- `brotli` and `zstd` are Elide additions.
- Formats are case-sensitive; an unknown format throws `TypeError`.
- Chunks must be `BufferSource` values.
- Malformed or truncated input rejects, as does decompressed output past a size limit.

For Buffer and callback APIs, see [node:zlib](https://elide.help/docs/api-node-zlib).

## Samples

- [Gzip with CompressionStream](https://elide.help/docs/code-samples#gzip-with-compressionstream)

<!-- api-reference:start a7589712fcbb -->
## Reference

**Status:** Full · Not measured · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `CompressionStream` | class | Full | `readable`, `writable` |
| `DecompressionStream` | class | Full | `readable`, `writable` |
<!-- api-reference:end -->
