Straight-forward way to reimplement fs.promises.open
#29109
Labels
feature request
Issues that request new features to be added to Node.js.
fs
Issues and PRs related to the fs subsystem / file system.
Is your feature request related to a problem? Please describe.
I have a PR open against
graceful-fs
which (among other updates) adds support forfs.promises
. A sticky point is the implementation ofgracefulFS.promises.open
. We need this to create an object that extendsFileHandle
fromlib/internal/fs/promises.js
.Describe the solution you'd like
Directly expose
class FileHandle
frominternal/fs/promises.js
asfs.promises.FileHandle
to allow extending. Alter the constructor to detect a numericfilehandle
:This would allow implementing a user-space
fs.promises.open
with a function based on a promisifiedfs.open
function. In this scheme settingfs.promises.FileHandle
would not alter the functionality offs.promises.open
.Describe alternatives you've considered
Current PR at isaacs/node-graceful-fs#173 does some very ugly stuff in promises.js to implement
fs.promises.open
which resolves to an extended class based on fs.promises.FileHandle. First it retrieves the C++ file handle class fromprocess.binding('fs').FileHandle
even thoughprocess.binding
is heading for deprecation. Worse it usesfs.promises.open(__filename, 'r')
to create a filehandle which is used to retrieveclass FileHandle
fromlib/internal/fs/promises.js
, then extends that class. A temporarypromises.open
method is created which awaits creation of the real method. This hacky method would be required to supportrequire('graceful-fs').promises
for current versions of node.js, but it would be nice iffs.promises.FileHandle
could be detected to avoid all the hacks/deprecated API's.I had considered a completely user-space implementation of
gracefulFS.promises
based onutil.promisify
but this would get really messy to reimplementfs.promises
functions which acceptfilehandle
, would potentially cause file handles returned bygracefulFS.promises.open
to be incompatible with nativefs.promises
methods.fs.promises.readFile
for example accepts a filehandle as the first argument, I'm unsure how it would react to a userspace implementation of the file handle. The user-space implementation would also fail to close FD's upon garbage collection (I don't agree with this auto-close feature but it exists).The text was updated successfully, but these errors were encountered: