-
-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Creating and recognizing fs/promises FileHandle objects #43821
Copy link
Copy link
Closed as not planned
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
Metadata
Metadata
Assignees
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
What is the problem this feature will solve?
I have modules that both accept and produce raw file descriptors. It would be nice to be able to leverage the fs/promises FileHandle wrapper to help prevent accidental file descriptor leaks due to user error. Unfortunately there is no clean way to wrap a raw file descriptor into a FileHandle nor to even reliably recognize a FileHandle when passed as argument.
The following wrapper around fs/promises adds functions for these purposes:
but needless to say this is horrifying.
What is the feature you are proposing to solve the problem?
Either add two functions to:
or export the FileHandle class and change its constructor to support
new FileHandle( fd )What alternatives have you considered?
Reimplementing similar functionality is possible using WeakRefs and FinalizationRegistry, but it seems unproductive to make an incompatible reimplementation of a class that's already implemented by nodejs itself, and it doesn't fix the problem of recognizing instances of the nodejs FileHandle when a user passes one.