node:zlib

Node.js zlib module, resolvable via both ESM import and CommonJS require under the bare (zlib) and prefixed (node:zlib) specifiers.

Unlike node:os, node:crypto, or node:path, Elide does not ship a native implementation of node:zlib. The module name is registered as a recognised Node built-in (NodeModuleName.ZLIB, packages/base/main/dev/elide/lang/javascript/loader/ElideUniversalJsModuleLoader.kt:180), but no Elide module provider claims it: JavaScriptLang.initAllModules() (packages/base/main/dev/elide/lang/javascript/JavaScriptLang.kt:49) registers no NodeZlibModule, and there is no node/zlib/ package. When a zlib / node:zlib request reaches the loader, ElideUniversalJsModuleLoader.synthesizeInjected finds no entry in ModuleRegistry, sees the node prefix, and delegates to the upstream NpmCompatibleESModuleLoader — i.e. the GraalJS built-in zlib (ElideUniversalJsModuleLoader.kt:218-228). Behaviour, supported options, and error semantics are therefore whatever the bundled GraalJS provides, not an Elide guarantee.

Relationship to Elide's native compression layer

Elide does ship a native DEFLATE-family compression layer (dev.elide.lang.javascript.compression.CompressionPrimitives — JDK fallback plus an FFM-Rust backend covering DEFLATE, GZIP, Brotli and Zstd; see Compression primitives). That layer backs the WHATWG CompressionStream / DecompressionStream globals. It is not wired into node:zlib; the two are independent paths. Code that needs Elide's native, bomb-defended codecs should reach for CompressionStream rather than node:zlib.

Backing

ConcernBacking
Module resolutionGraalJS built-in, via fall-through in ElideUniversalJsModuleLoader
ImplementationUpstream GraalJS zlib; no Elide-side code
Native compression backend (CompressionPrimitives)Not connected to node:zlib

Availability

Because the module is served by GraalJS, the precise surface tracks the bundled GraalJS release rather than Elide. The commonly exercised entry points are the zlib-family one-shot helpers and their stream constructors:
AreaOperations
Deflate / Inflate (sync + async)deflate, deflateSync, inflate, inflateSync, deflateRaw, deflateRawSync, inflateRaw, inflateRawSync
Gzip / Gunzip / Unzip (sync + async)gzip, gzipSync, gunzip, gunzipSync, unzip, unzipSync
Stream constructorscreateDeflate, createInflate, createDeflateRaw, createInflateRaw, createGzip, createGunzip, createUnzip
Brotli (sync + async)brotliCompress, brotliCompressSync, brotliDecompress, brotliDecompressSync, createBrotliCompress, createBrotliDecompress
Constantsconstants (zlib Z_, Brotli BROTLI_ numeric tables)
Support for any specific function — particularly Brotli, which depends on a native codec, and any Zstd surface — is determined by the bundled GraalJS build and is not something Elide independently guarantees. Verify the operations you depend on against the runtime you ship; do not assume the full upstream Node surface is present. The async forms are callback-style ((err, result)); the Sync forms return a Buffer and throw on error.

Example

javascript
const zlib = require("node:zlib");

// One-shot gzip round-trip (synchronous).
const input = Buffer.from("hello, zlib!");
const gzipped = zlib.gzipSync(input);
const restored = zlib.gunzipSync(gzipped);
restored.toString(); // → "hello, zlib!"

// Async deflate.
zlib.deflate(input, (err, deflated) => {
  if (err) throw err;
  zlib.inflate(deflated, (err2, back) => {
    if (err2) throw err2;
    back.toString(); // → "hello, zlib!"
  });
});

Not provided by Elide

These are not Elide-implemented and exist only insofar as the bundled GraalJS provides them; Elide adds nothing on top and makes no compatibility promise:

  • Class constructors (Deflate, Inflate, Gzip, Gunzip, Unzip, BrotliCompress, BrotliDecompress, …).
  • Zstd operations (zstdCompress, zstdDecompress, createZstd*).
  • crc32, codes, preset-dictionary and advanced windowBits / memLevel options, and the full Brotli encoder/decoder parameter set.

A WebIDL surface describing a future native node:zlib (protocol/webidl/node/zlib.webidl, generated into packages/generated/.../node/JSZlibNamespaceBase.java) exists in the tree, but nothing extends or registers it yet — it is a scaffold, not a live code path. When that surface is wired up, this page will be updated to document Elide's own implementation and its guarantees.

node:zlib/iter (Elide extension)

node:zlib/iter is an Elide-specific specifier (not part of Node) that provides async-iterator transforms built on the WHATWG CompressionStream / DecompressionStream. Each factory returns a transform that maps one async iterable of byte chunks to another:
FactoryTransform
gzip()gzip compress
gunzip()gzip decompress
deflate()zlib deflate
inflate()zlib inflate
deflateRaw()raw deflate
inflateRaw()raw inflate
javascript
import { gzip } from "node:zlib/iter";

async function* chunks() {
  yield new TextEncoder().encode("hello");
}

for await (const out of gzip()(chunks())) {
  // out: compressed byte chunk
}

See also