Skip to content

Commit c914d95

Browse files
cjihrigdanielleadams
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 9242c19 commit c914d95

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

doc/api/fs.md

+22-19
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,11 @@ added: v10.0.0
689689
690690
Tests a user's permissions for the file or directory specified by `path`.
691691
The `mode` argument is an optional integer that specifies the accessibility
692-
checks to be performed. Check [File access constants][] for possible values
693-
of `mode`. It is possible to create a mask consisting of the bitwise OR of
694-
two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
692+
checks to be performed. `mode` should be either the value `fs.constants.F_OK`
693+
or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,
694+
`fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
695+
`fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
696+
possible values of `mode`.
695697
696698
If the accessibility check is successful, the promise is resolved with no
697699
value. If any of the accessibility checks fail, the promise is rejected
@@ -1561,9 +1563,11 @@ changes:
15611563
15621564
Tests a user's permissions for the file or directory specified by `path`.
15631565
The `mode` argument is an optional integer that specifies the accessibility
1564-
checks to be performed. Check [File access constants][] for possible values
1565-
of `mode`. It is possible to create a mask consisting of the bitwise OR of
1566-
two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
1566+
checks to be performed. `mode` should be either the value `fs.constants.F_OK`
1567+
or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,
1568+
`fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
1569+
`fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
1570+
possible values of `mode`.
15671571
15681572
The final argument, `callback`, is a callback function that is invoked with
15691573
a possible error argument. If any of the accessibility checks fail, the error
@@ -1590,14 +1594,9 @@ access(file, constants.W_OK, (err) => {
15901594
console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
15911595
});
15921596
1593-
// Check if the file exists in the current directory, and if it is writable.
1594-
access(file, constants.F_OK | constants.W_OK, (err) => {
1595-
if (err) {
1596-
console.error(
1597-
`${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
1598-
} else {
1599-
console.log(`${file} exists, and it is writable`);
1600-
}
1597+
// Check if the file is readable and writable.
1598+
access(file, constants.R_OK | constants.W_OK, (err) => {
1599+
console.log(`${file} ${err ? 'is not' : 'is'} readable and writable`);
16011600
});
16021601
```
16031602
@@ -4389,10 +4388,11 @@ changes:
43894388
43904389
Synchronously tests a user's permissions for the file or directory specified
43914390
by `path`. The `mode` argument is an optional integer that specifies the
4392-
accessibility checks to be performed. Check [File access constants][] for
4393-
possible values of `mode`. It is possible to create a mask consisting of
4394-
the bitwise OR of two or more values
4395-
(e.g. `fs.constants.W_OK | fs.constants.R_OK`).
4391+
accessibility checks to be performed. `mode` should be either the value
4392+
`fs.constants.F_OK` or a mask consisting of the bitwise OR of any of
4393+
`fs.constants.R_OK`, `fs.constants.W_OK`, and `fs.constants.X_OK` (e.g.
4394+
`fs.constants.W_OK | fs.constants.R_OK`). Check [File access constants][] for
4395+
possible values of `mode`.
43964396
43974397
If any of the accessibility checks fail, an `Error` will be thrown. Otherwise,
43984398
the method will return `undefined`.
@@ -6502,7 +6502,8 @@ open('/path/to/my/file', O_RDWR | O_CREAT | O_EXCL, (err, fd) => {
65026502
65036503
##### File access constants
65046504
6505-
The following constants are meant for use with [`fs.access()`][].
6505+
The following constants are meant for use as the `mode` parameter passed to
6506+
[`fsPromises.access()`][], [`fs.access()`][], and [`fs.accessSync()`][].
65066507
65076508
<table>
65086509
<tr>
@@ -7181,6 +7182,7 @@ the file contents.
71817182
[`event ports`]: https://illumos.org/man/port_create
71827183
[`filehandle.writeFile()`]: #filehandlewritefiledata-options
71837184
[`fs.access()`]: #fsaccesspath-mode-callback
7185+
[`fs.accessSync()`]: #fsaccesssyncpath-mode
71847186
[`fs.chmod()`]: #fschmodpath-mode-callback
71857187
[`fs.chown()`]: #fschownpath-uid-gid-callback
71867188
[`fs.copyFile()`]: #fscopyfilesrc-dest-mode-callback
@@ -7215,6 +7217,7 @@ the file contents.
72157217
[`fs.write(fd, string...)`]: #fswritefd-string-position-encoding-callback
72167218
[`fs.writeFile()`]: #fswritefilefile-data-options-callback
72177219
[`fs.writev()`]: #fswritevfd-buffers-position-callback
7220+
[`fsPromises.access()`]: #fspromisesaccesspath-mode
72187221
[`fsPromises.open()`]: #fspromisesopenpath-flags-mode
72197222
[`fsPromises.opendir()`]: #fspromisesopendirpath-options
72207223
[`fsPromises.rm()`]: #fspromisesrmpath-options

0 commit comments

Comments
 (0)