Skip to content

node:zlib: implement Zstd codecs beyond export shapes #2510

Description

@andrewtdiz

Summary

Most of Perry's node:zlib surface has been filled in, but the Node 22+ Zstd APIs are currently only exposed as shapes. The ZstdCompress / ZstdDecompress classes and createZstd* factory names exist for typeof checks, but there is no runtime codec implementation or native-table dispatch for Zstd compression/decompression.

Node Behavior

Modern Node exposes Zstd one-shot and stream APIs alongside the existing gzip/deflate/Brotli families:

const zlib = require("node:zlib");
const input = Buffer.from("perry zstd roundtrip");

console.log(typeof zlib.ZstdCompress);
console.log(typeof zlib.ZstdDecompress);
console.log(typeof zlib.createZstdCompress);
console.log(typeof zlib.createZstdDecompress);
console.log(typeof zlib.zstdCompressSync);
console.log(typeof zlib.zstdDecompressSync);

const compressed = zlib.zstdCompressSync(input);
console.log(zlib.zstdDecompressSync(compressed).toString());

Callback forms and Transform factories should follow the same Node zlib family semantics for the covered round-trip cases.

Perry Behavior

  • test-files/test_parity_zlib.ts probes zlib.ZstdCompress, zlib.ZstdDecompress, createZstdCompress, createZstdDecompress, zstdCompressSync, zstdDecompressSync, zstdCompress, and zstdDecompress.
  • crates/perry-api-manifest/src/entries.rs registers class("zlib", "ZstdCompress"), class("zlib", "ZstdDecompress"), zlib_stream_factory("createZstdCompress"), and zlib_stream_factory("createZstdDecompress"), but there are no zstdCompress, zstdDecompress, zstdCompressSync, or zstdDecompressSync manifest entries.
  • crates/perry-runtime/src/object/native_module.rs lists ZstdCompress, ZstdDecompress, createZstdCompress, and createZstdDecompress in the callable export whitelist, which makes property reads look function-shaped.
  • crates/perry-codegen/src/lower_call/native_table/media.rs has runtime rows for gzip/gunzip/deflate/inflate/raw/unzip and Brotli factories, but no createZstdCompress or createZstdDecompress rows.
  • crates/perry-stdlib/src/zlib.rs has stream codecs for gzip/gunzip/deflate/inflate/raw/unzip/Brotli, but no Codec::Zstd*, no js_zlib_create_zstd_*, and no one-shot Zstd functions.

Suggested PR Cut

Batch this with related issues in:
node:zlib: Zstd codec parity cut

Good batch candidates:

  • none currently filed; this issue is the Zstd cut seed

Do not batch with:

Acceptance

  • parity/regression test proves Zstd sync one-shot compression/decompression round-trips deterministic input
  • callback-form Zstd APIs and util.promisify() behavior match Node for covered cases, or are explicitly staged with follow-up leaves if not included in the first Zstd PR
  • createZstdCompress() / createZstdDecompress() are real Transform-compatible handles for covered round-trip cases
  • ZstdCompress / ZstdDecompress constructors match the surrounding zlib class export behavior for covered cases
  • related known-failure/docs/manifest entries updated if touched

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions