diff --git a/doc/api/fs.md b/doc/api/fs.md index 3543608c6ea508..47491cf5a742c7 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -679,19 +679,19 @@ Tests a user's permissions for the file or directory specified by `path`. The `mode` argument is an optional integer that specifies the accessibility checks to be performed. The following constants define the possible values of `mode`. It is possible to create a mask consisting of the bitwise OR of two or -more values. +more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`). -- `fs.constants.F_OK` - `path` is visible to the calling process. This is useful +* `fs.constants.F_OK` - `path` is visible to the calling process. This is useful for determining if a file exists, but says nothing about `rwx` permissions. Default if no `mode` is specified. -- `fs.constants.R_OK` - `path` can be read by the calling process. -- `fs.constants.W_OK` - `path` can be written by the calling process. -- `fs.constants.X_OK` - `path` can be executed by the calling process. This has +* `fs.constants.R_OK` - `path` can be read by the calling process. +* `fs.constants.W_OK` - `path` can be written by the calling process. +* `fs.constants.X_OK` - `path` can be executed by the calling process. This has no effect on Windows (will behave like `fs.constants.F_OK`). The final argument, `callback`, is a callback function that is invoked with a possible error argument. If any of the accessibility checks fail, the error -argument will be populated. The following example checks if the file +argument will be an `Error` object. The following example checks if the file `/etc/passwd` can be read and written by the current process. ```js @@ -783,7 +783,7 @@ The "not recommended" examples above check for accessibility and then use the file; the "recommended" examples are better because they use the file directly and handle the error, if any. -In general, check for the accessibility of a file only if the file won’t be +In general, check for the accessibility of a file only if the file will not be used directly, for example when its accessibility is a signal from another process. @@ -799,9 +799,33 @@ changes: * `path` {string|Buffer|URL} * `mode` {integer} **Default:** `fs.constants.F_OK` +* Returns: `undefined` -Synchronous version of [`fs.access()`][]. This throws if any accessibility -checks fail, and does nothing otherwise. +Synchronously tests a user's permissions for the file or directory specified by +`path`. The `mode` argument is an optional integer that specifies the +accessibility checks to be performed. The following constants define the +possible values of `mode`. It is possible to create a mask consisting of the +bitwise OR of two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`). + +* `fs.constants.F_OK` - `path` is visible to the calling process. This is useful +for determining if a file exists, but says nothing about `rwx` permissions. +Default if no `mode` is specified. +* `fs.constants.R_OK` - `path` can be read by the calling process. +* `fs.constants.W_OK` - `path` can be written by the calling process. +* `fs.constants.X_OK` - `path` can be executed by the calling process. This has +no effect on Windows (will behave like `fs.constants.F_OK`). + +If any of the accessibility checks fail, an `Error` will be thrown. Otherwise, +the method will return `undefined`. + +```js +try { + fs.accessSync('etc/passwd', fs.constants.R_OK | fs.constants.W_OK); + console.log('can read/write'); +} catch (err) { + console.error('no access!'); +} +``` ## fs.appendFile(file, data[, options], callback)