# node:zlib

The `node:zlib` module compresses and decompresses data with the Gzip, Deflate, and Brotli algorithms, and Node.js builds it on the zlib library, as the [Node.js zlib documentation](https://nodejs.org/api/zlib.html) describes. In Azion Runtime, `import zlib from "node:zlib"` builds, and `zlib.constants` is an object, in a deployed function and under `azion dev`.

The compression functions are not implemented, so nothing in the module compresses data. Each one throws an `Error` or passes one to its callback, with the same message in a deployed function and under `azion dev`.

To compress data in a function, use the Web `CompressionStream` API, which works in both environments. A `new CompressionStream('gzip')` stream compresses the data, and a `new DecompressionStream('gzip')` stream restores it. The constructor accepts `gzip`, `deflate`, and `deflate-raw`, and throws a `TypeError` for `br`. For more information, refer to [Web APIs](/en/documentation/devtools/runtime/api-reference/javascript/).

---

## Methods

The table lists each compression function and the error it produces:

| Call                            | Result                                                                       |
| ------------------------------- | ---------------------------------------------------------------------------- |
| `zlib.gzipSync(data)`           | Throws `Error: [unenv] zlib.gzipSync is not implemented yet!`                |
| `zlib.deflateSync(data)`        | Throws `Error: [unenv] zlib.deflateSync is not implemented yet!`             |
| `zlib.deflateRawSync(data)`     | Throws `Error: [unenv] zlib.deflateRawSync is not implemented yet!`          |
| `zlib.brotliCompressSync(data)` | Throws `Error: [unenv] zlib.brotliCompressSync is not implemented yet!`      |
| `zlib.gzip(data, callback)`     | Calls `callback` with `Error: [unenv] zlib gzip compression not supported.`  |
| `zlib.createGzip()`             | Throws `Error: [unenv] zlib is not implemented yet! is not implemented yet!` |

---

## Related resources

- [Node.js APIs](/en/documentation/devtools/runtime/node.md): Every Node.js module Azion Runtime resolves, and how each one behaves.
- [Web APIs](/en/documentation/devtools/runtime/api-reference/javascript.md): The Web APIs a function can call, the stream APIs among them.
- [Globals](/en/documentation/devtools/runtime/api-reference/azion-runtime-globals.md): The global objects of Azion Runtime, which include `CompressionStream` and `DecompressionStream`.
- [Use Node.js APIs through polyfills](/en/documentation/guides/application-development/functions-and-runtime/use-polyfills.md): How the build resolves Node.js APIs through polyfills, shown in a JavaScript project.
