feat: replace peek-stream with native node:stream#394
Open
hardik-kaji wants to merge 2 commits intofastify:mainfrom
Open
feat: replace peek-stream with native node:stream#394hardik-kaji wants to merge 2 commits intofastify:mainfrom
hardik-kaji wants to merge 2 commits intofastify:mainfrom
Conversation
Remove the peek-stream dependency which pulls in through2 and xtend (EOL since 2015). Replace with a lightweight createPeekStream helper using node:stream.Duplex — zero new dependencies. This eliminates 3 transitive packages: peek-stream, through2, xtend.
This comment was marked as spam.
This comment was marked as spam.
|
Thank you for this. Unfortunately those EOL packages lead to quite some headaches within corporate environments, thus it's much easier to use fastify in those environments if it's clean. |
mcollina
requested changes
Apr 30, 2026
Member
mcollina
left a comment
There was a problem hiding this comment.
This seem expensive perf-wise. Maybe we can drop peek-stream and have a better interface for this?
Refactor createPeekStream into createLazyTransform: - Use Transform instead of Duplex for a simpler, idiomatic interface - Synchronous `choose(data)` replaces callback-based `swap(err, stream)` - Buffer chunks in an array, concat only once when threshold is reached - Default maxBuffer to 10 (the only value used in practice) - Rename to createLazyTransform to better reflect its purpose
b179ac3 to
c82c2f3
Compare
Author
@mcollina Done! Refactored createPeekStream into createLazyTransform with a simpler, more performant interface:
The callers are now much cleaner: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The peek-stream package depends on through2 and xtend — all of which are
legacy userland stream utilities. In particular, xtend is no longer maintained.
Removing peek-stream reduces the dependency tree, avoids maintenance/security risks
from unmaintained packages, and aligns with the ongoing effort (#386) to replace
userland stream helpers with native node:stream APIs.
Summary
implementation using node:stream Duplex
first maxBuffer bytes when a single write exceeded maxBuffer
unit tests
Changes
unused Duplex import
short streams, error propagation, empty streams, and transform destination
Checklist
npm run test && npm run benchmark --if-presentand the Code of conduct