-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Description
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.Direntfs.Statsfs.ReadStreamfs.WriteStreamfs.FileReadStreamfs.FileWriteStreamfs._toUnixTimestamp(could be excluded)fs.F_OK(could be excluded, I guess these 4 are here for historical reasons)fs.R_OKfs.W_OKfs.X_OKfs.constants