Skip to content

fix(ext/node): add zstd compression support to node:zlib#32025

Merged
bartlomieju merged 10 commits intodenoland:mainfrom
bartlomieju:zlib_zstd
Feb 3, 2026
Merged

fix(ext/node): add zstd compression support to node:zlib#32025
bartlomieju merged 10 commits intodenoland:mainfrom
bartlomieju:zlib_zstd

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

@bartlomieju bartlomieju commented Feb 3, 2026

This commit improves impl of node:zlib module by adding zstd compression support.

Several Node compat tests were enabled, more will be enabled in a follow up.

🤖 Generated with Claude Code

bartlomieju and others added 2 commits February 3, 2026 11:49
Implements Zstandard (zstd) compression and decompression support
for the Node.js compatibility layer. This adds ZstdCompress and
ZstdDecompress classes that work with Node's streaming zlib API.

- Add zstd dependency to ext/node
- Implement ZstdCompress and ZstdDecompress in Rust using zstd crate
- Export bindings via _zlib_binding.mjs
- Add ZSTD constants to internal_binding/constants.ts
- Update zlib.js to pass mode parameter to constructors

4 of 7 zstd tests now pass (flush, from-string, dictionary, from-zstd).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add ERR_ZSTD_INVALID_PARAM error class for invalid zstd parameters
- Make ERR_ZLIB_INITIALIZATION_FAILED accept custom message
- Validate zstd strategy values and return error on invalid params
- Check set_parameter return values and fail on error

5 of 7 zstd tests now pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add pledgedSrcSize parameter to ZstdCompress::init
- Set error code ZSTD_error_srcSize_wrong for size mismatch errors
- Catch errors in processChunk and emit via destroy() properly
- Add ERR_ZLIB_INITIALIZATION_FAILED to error codes

6 of 7 zstd tests now pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
bartlomieju and others added 2 commits February 3, 2026 12:27
Properly implement deprecateInstantiation to create and return
a new instance when zlib classes are called without `new`.
This allows proper error handling for invalid arguments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bartlomieju bartlomieju changed the title feat(ext/node): add zstd compression support to node:zlib fix(ext/node): add zstd compression support to node:zlib Feb 3, 2026
Comment on lines +1354 to +1356
// SAFETY: `write_result` is a valid pointer to a mutable slice of u32 of length 2.
unsafe {
let result = std::slice::from_raw_parts_mut(ctx.write_result, 2);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't check anywhere that length of write_result is infact not less than 2

@bartlomieju bartlomieju enabled auto-merge (squash) February 3, 2026 15:34
@bartlomieju bartlomieju merged commit b486c63 into denoland:main Feb 3, 2026
22 checks passed
@bartlomieju bartlomieju deleted the zlib_zstd branch February 3, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants