feat(node/fs): implement FileHandle.readableWebStream()#31745
Merged
bartlomieju merged 13 commits intodenoland:mainfrom Jan 8, 2026
Merged
feat(node/fs): implement FileHandle.readableWebStream()#31745bartlomieju merged 13 commits intodenoland:mainfrom
bartlomieju merged 13 commits intodenoland:mainfrom
Conversation
- 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
Contributor
Tango992
left a comment
There was a problem hiding this comment.
Thanks, LGTM! I'd commit some changes before merging so it would pass the node compat test
Member
|
Nice work! |
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.
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.