Skip to content

Conversation

@mcollina
Copy link
Member

@mcollina mcollina commented Jul 1, 2025

Summary

This PR implements zstd compression support for @fastify/compress, addressing issue #365.

Key Features:

  • Conditional zstd support - Only available on Node.js 22.15+ and 23.8+ where zlib.createZstdCompress exists
  • Proper priority ordering - zstd gets highest priority when available
  • Full compression/decompression - Both request and response compression supported
  • Magic byte detection - Added isZstd() utility for RFC 8878 compliant format detection
  • TypeScript support - Updated type definitions to include 'zstd' encoding
  • Backward compatibility - Works seamlessly with existing Node.js versions that don't have zstd

Implementation Details:

  • Added conditional zstd stream creation in both compression and decompression paths
  • Updated supported encodings arrays to include zstd when available
  • Added comprehensive tests for compression, decompression, and utility functions
  • Updated TypeScript definitions and tests
  • Added package.json keyword

Files Modified:

  • index.js - Core zstd support implementation
  • lib/utils.js - Added isZstd() utility function
  • types/index.d.ts - Updated TypeScript definitions
  • types/index.test-d.ts - Added TypeScript tests
  • test/global-compress.test.js - Added zstd compression tests
  • test/global-decompress.test.js - Added zstd decompression tests
  • test/utils.test.js - Added zstd utility tests
  • package.json - Added 'zstd' keyword
  • CLAUDE.md - Updated documentation

Test plan

  • All existing tests pass
  • New zstd compression tests pass on Node.js 22.15+
  • zstd tests are properly skipped on older Node.js versions
  • TypeScript definitions are validated
  • Linting passes
  • Manual testing confirms zstd compression works

🤖 Generated with Claude Code

Fixes #365

mcollina and others added 2 commits July 1, 2025 11:10
- Add conditional zstd support for Node.js 22.15+/23.8+
- Implement zstd compression/decompression streams
- Add isZstd() utility for magic byte detection (RFC 8878)
- Update TypeScript definitions to include 'zstd' encoding
- Add comprehensive tests for zstd compression and decompression
- Update package.json keywords and documentation
- Maintain backward compatibility with older Node.js versions

Fixes #365

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Matteo Collina <[email protected]>
- Add zstd to supported encodings list with Node.js version requirements
- Update encoding priority order to include zstd as highest priority
- Add examples showing zstd usage for both response compression and request decompression
- Document zstd availability for Node.js 22.15+/23.8+

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Matteo Collina <[email protected]>
@mcollina mcollina merged commit 0276b86 into main Jul 1, 2025
17 checks passed
@mcollina mcollina deleted the feat/add-zstd-support branch July 1, 2025 10:55
@Rdataflow
Copy link

@mcollina wow your reaction is so minblowing fast, great work 🚀
NB: maybe you can give your review on #363 this would help a lot 🙇

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.

feat: add support for zstd compression

3 participants