Skip to content

fs/promises API inconsitency (.close not there) #20548

Closed
@ChALkeR

Description

Currently, fs/promises provides a nearly identical API to fs, minus callbacks → promises change (obvious) and the fdfilenandle change (mostly invisible in most usecases).

The following parts of fs API are not present on fs/promises:

  • *Sync methods (obvious)
  • non-functions (ok)
  • exists — kinda ok, since it was deprecated and never worked in a promisified variant. access is there.
  • *Stream — well, kinda ok, not a promise.
  • *watch* — also ok, it doesn't behave like promises.
  • close — why?

All the other methods, except close, that are present on filehandle objects and in callback-based fs API are also present directly as methods of fs/promises API, accepting a filehandle. I assume that was done to ease the migration and provide 1:1 mapping between those where sensible, e.g. for people who were previously using promisified fs versions.

I don't see how close is different from other filehandle APIs, so in my opinion either of there two should happen:

  • All the methods of fs/promises that accept a filehandle should be dropped in favor of the same methods on filehandle objects.
    This will avoid overcomplicating things, will declutter the docs and will save time future users figuring out the «canonical» way to do something.
  • fs/promises should have as much of direct fs API duplicates as reasonable — basically, what we have now + .close should be added.
    This will ease migration for people who are already using the current fs API with (or without) promisify.

/cc @jasnell @Trott @BridgeAR

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    experimentalIssues and PRs related to experimental features.fsIssues and PRs related to the fs subsystem / file system.promisesIssues and PRs related to ECMAScript promises.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions