Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fully decorated fs.promises for complete fs replacement? #28545

Copy link
Copy link
@rvagg

Description

@rvagg
Issue body actions

I've got into the habit of const fs = require('fs').promises, which is fine for the most part for nice async / await code. But since it's not decorated with the fs properties other than promisified versions of the core functions that usefulness breaks down.

The main one is fs.constants, the other ones don't tend to be used directly but there is a case to be made for exposing them too.

With the current interface I can't do this kind of thing, which would implement an await touch(file):

const fs = require('fs').promises

module.exports = function touch (f) {
  return fs.access(f, fs.constants.F_OK).catch(() => fs.writeFile(f, Buffer.alloc(0)))
}

I can achieve this if I manually decorate it with fs.constants = require('fs').constants. So it's not super terrible, just inconvenient and means that require('fs').promises isn't a fully viable require('fs') replacement for async functions.

Has this come up? Have we come up with a consistent philosophy for fs.promises that would preclude this? Or should I (or someone else) cook up a PR to make this work with the more fs decorations? constants at least.

Current decorations excluding the standard functions and promises are:

  • fs.Dirent
  • fs.Stats
  • fs.ReadStream
  • fs.WriteStream
  • fs.FileReadStream
  • fs.FileWriteStream
  • fs._toUnixTimestamp (could be excluded)
  • fs.F_OK (could be excluded, I guess these 4 are here for historical reasons)
  • fs.R_OK
  • fs.W_OK
  • fs.X_OK
  • fs.constants
BridgeAR, sindresorhus, DRoet, danielearwicker, opl- and 4 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.promisesIssues and PRs related to ECMAScript promises.Issues 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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.