-
Notifications
You must be signed in to change notification settings - Fork 5.9k
feat(node/fs): implement FileHandle.readableWebStream() #31745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tt-a1i
wants to merge
12
commits into
denoland:main
Choose a base branch
from
tt-a1i:filehandle-readable-webstream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+256
−4
Conversation
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
- Fix autoClose: listen to 'end' event instead of 'close' (close doesn't fire with autoClose:false) - Add one-time lock protection: throw ERR_INVALID_STATE when called twice - Remove unused 'type' parameter from options - Handle potential unhandled rejection in autoClose callback - Improve tests: wait for close event and assert fd === -1 instead of setTimeout
- Use new ReadableStream({ type: 'bytes', pull, cancel }) directly
- Call FileHandle.read() in pull instead of using Readable.toWeb(createReadStream)
- Properly handle both EOF and cancel() for autoClose
- Add kRef/kUnref for proper resource management
- Add tests for cancel semantics with and without autoClose
This aligns with Node v22.17.0 implementation and avoids the side effects
of createReadStream's _destroy closing the fd directly.
- Save controller reference in start() - On FileHandle close, call controller.error() which works even when locked - Add test for closing FileHandle while reader is active
FileHandle extends EventEmitter but the TypeScript type definition doesn't expose the once() method. Use type assertion to fix type checking errors.
Tango992
approved these changes
Jan 8, 2026
Member
Tango992
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM! I'd commit some changes before merging so it would pass the node compat test
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.
Summary
Implements
FileHandle.readableWebStream()method for Node.js compatibility.This method returns a Web Streams API
ReadableStreamthat can be used to read the file contents. It supports theautoCloseoption which, when true, will automatically close the FileHandle when the stream is fully consumed.Closes #25554 (partially - this addresses one of the remaining unimplemented methods)
Changes
readableWebStream()method toFileHandleclass inext/node/polyfills/internal/fs/handle.tstests/unit_node/_fs/_fs_handle_test.tsTest Plan
readableWebStream()functionalityautoClose: trueoptionAI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.