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

Commit f443a4e

Browse filesBrowse files
cjihrigtargos
authored andcommitted
doc: expand fs.access() mode parameter docs
This commit expands the documentation for the mode parameter passed to the fs.access() family of functions. PR-URL: #41484 Refs: libuv/libuv#3410 Reviewed-By: Richard Lau Reviewed-By: Luigi Pinca Reviewed-By: Tobias Nießen
1 parent 9d8d7c6 commit f443a4e
Copy full SHA for f443a4e

File tree

Expand file treeCollapse file tree

1 file changed

+22
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-19
lines changed
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+22-19Lines changed: 22 additions & 19 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,11 @@ added: v10.0.0
738738
739739
Tests a user's permissions for the file or directory specified by `path`.
740740
The `mode` argument is an optional integer that specifies the accessibility
741-
checks to be performed. Check [File access constants][] for possible values
742-
of `mode`. It is possible to create a mask consisting of the bitwise OR of
743-
two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
741+
checks to be performed. `mode` should be either the value `fs.constants.F_OK`
742+
or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,
743+
`fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
744+
`fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
745+
possible values of `mode`.
744746
745747
If the accessibility check is successful, the promise is resolved with no
746748
value. If any of the accessibility checks fail, the promise is rejected
@@ -1616,9 +1618,11 @@ changes:
16161618
16171619
Tests a user's permissions for the file or directory specified by `path`.
16181620
The `mode` argument is an optional integer that specifies the accessibility
1619-
checks to be performed. Check [File access constants][] for possible values
1620-
of `mode`. It is possible to create a mask consisting of the bitwise OR of
1621-
two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
1621+
checks to be performed. `mode` should be either the value `fs.constants.F_OK`
1622+
or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,
1623+
`fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
1624+
`fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
1625+
possible values of `mode`.
16221626
16231627
The final argument, `callback`, is a callback function that is invoked with
16241628
a possible error argument. If any of the accessibility checks fail, the error
@@ -1645,14 +1649,9 @@ access(file, constants.W_OK, (err) => {
16451649
console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
16461650
});
16471651
1648-
// Check if the file exists in the current directory, and if it is writable.
1649-
access(file, constants.F_OK | constants.W_OK, (err) => {
1650-
if (err) {
1651-
console.error(
1652-
`${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
1653-
} else {
1654-
console.log(`${file} exists, and it is writable`);
1655-
}
1652+
// Check if the file is readable and writable.
1653+
access(file, constants.R_OK | constants.W_OK, (err) => {
1654+
console.log(`${file} ${err ? 'is not' : 'is'} readable and writable`);
16561655
});
16571656
```
16581657
@@ -4459,10 +4458,11 @@ changes:
44594458
44604459
Synchronously tests a user's permissions for the file or directory specified
44614460
by `path`. The `mode` argument is an optional integer that specifies the
4462-
accessibility checks to be performed. Check [File access constants][] for
4463-
possible values of `mode`. It is possible to create a mask consisting of
4464-
the bitwise OR of two or more values
4465-
(e.g. `fs.constants.W_OK | fs.constants.R_OK`).
4461+
accessibility checks to be performed. `mode` should be either the value
4462+
`fs.constants.F_OK` or a mask consisting of the bitwise OR of any of
4463+
`fs.constants.R_OK`, `fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
4464+
`fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
4465+
possible values of `mode`.
44664466
44674467
If any of the accessibility checks fail, an `Error` will be thrown. Otherwise,
44684468
the method will return `undefined`.
@@ -6579,7 +6579,8 @@ open('/path/to/my/file', O_RDWR | O_CREAT | O_EXCL, (err, fd) => {
65796579
65806580
##### File access constants
65816581
6582-
The following constants are meant for use with [`fs.access()`][].
6582+
The following constants are meant for use as the `mode` parameter passed to
6583+
[`fsPromises.access()`][], [`fs.access()`][], and [`fs.accessSync()`][].
65836584
65846585
<table>
65856586
<tr>
@@ -7258,6 +7259,7 @@ the file contents.
72587259
[`event ports`]: https://illumos.org/man/port_create
72597260
[`filehandle.writeFile()`]: #filehandlewritefiledata-options
72607261
[`fs.access()`]: #fsaccesspath-mode-callback
7262+
[`fs.accessSync()`]: #fsaccesssyncpath-mode
72617263
[`fs.chmod()`]: #fschmodpath-mode-callback
72627264
[`fs.chown()`]: #fschownpath-uid-gid-callback
72637265
[`fs.copyFile()`]: #fscopyfilesrc-dest-mode-callback
@@ -7292,6 +7294,7 @@ the file contents.
72927294
[`fs.write(fd, string...)`]: #fswritefd-string-position-encoding-callback
72937295
[`fs.writeFile()`]: #fswritefilefile-data-options-callback
72947296
[`fs.writev()`]: #fswritevfd-buffers-position-callback
7297+
[`fsPromises.access()`]: #fspromisesaccesspath-mode
72957298
[`fsPromises.open()`]: #fspromisesopenpath-flags-mode
72967299
[`fsPromises.opendir()`]: #fspromisesopendirpath-options
72977300
[`fsPromises.rm()`]: #fspromisesrmpath-options

0 commit comments

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