| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -789,8 +789,7 @@ with an {Error} object. The following example checks if the file | |||
| 789 | 789 | `/etc/passwd` can be read and written by the current process. | |
| 790 | 790 | ||
| 791 | 791 | ```mjs | |
| 792 | - import { access } from 'node:fs/promises'; | ||
| 793 | - import { constants } from 'node:fs'; | ||
| 792 | + import { access, constants } from 'node:fs/promises'; | ||
| 794 | 793 | ||
| 795 | 794 | try { | |
| 796 | 795 | await access('/etc/passwd', constants.R_OK | constants.W_OK); | |
@@ -892,8 +891,7 @@ error occurs after the destination file has been opened for writing, an attempt | |||
| 892 | 891 | will be made to remove the destination. | |
| 893 | 892 | ||
| 894 | 893 | ```mjs | |
| 895 | - import { constants } from 'node:fs'; | ||
| 896 | - import { copyFile } from 'node:fs/promises'; | ||
| 894 | + import { copyFile, constants } from 'node:fs/promises'; | ||
| 897 | 895 | ||
| 898 | 896 | try { | |
| 899 | 897 | await copyFile('source.txt', 'destination.txt'); | |
@@ -1622,6 +1620,14 @@ try { | |||
| 1622 | 1620 | Aborting an ongoing request does not abort individual operating | |
| 1623 | 1621 | system requests but rather the internal buffering `fs.writeFile` performs. | |
| 1624 | 1622 | ||
| 1623 | + ### `fsPromises.constants` | ||
| 1624 | + | ||
| 1625 | + * {Object} | ||
| 1626 | + | ||
| 1627 | + Returns an object containing commonly used constants for file system | ||
| 1628 | + operations. The object is the same as `fs.constants`. See [FS constants][] | ||
| 1629 | + for more details. | ||
| 1630 | + | ||
| 1625 | 1631 | ## Callback API | |
| 1626 | 1632 | ||
| 1627 | 1633 | The callback APIs perform all operations asynchronously, without blocking the | |
@@ -6879,7 +6885,7 @@ operations. | |||
| 6879 | 6885 | ||
| 6880 | 6886 | #### FS constants | |
| 6881 | 6887 | ||
| 6882 | - The following constants are exported by `fs.constants`. | ||
| 6888 | + The following constants are exported by `fs.constants` and `fsPromises.constants`. | ||
| 6883 | 6889 | ||
| 6884 | 6890 | Not every constant will be available on every operating system; | |
| 6885 | 6891 | this is especially important for Windows, where many of the POSIX specific | |
@@ -7584,6 +7590,7 @@ the file contents. | |||
| 7584 | 7590 | ||
| 7585 | 7591 | [#25741]: https://github.com/nodejs/node/issues/25741 | |
| 7586 | 7592 | [Common System Errors]: errors.md#common-system-errors | |
| 7593 | + [FS constants]: #fs-constants | ||
| 7587 | 7594 | [File access constants]: #file-access-constants | |
| 7588 | 7595 | [MDN-Date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date | |
| 7589 | 7596 | [MDN-Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,13 +17,15 @@ const { | |||
| 17 | 17 | Uint8Array, | |
| 18 | 18 | } = primordials; | |
| 19 | 19 | ||
| 20 | + const { fs: constants } = internalBinding('constants'); | ||
| 20 | 21 | const { | |
| 21 | 22 | F_OK, | |
| 22 | 23 | O_SYMLINK, | |
| 23 | 24 | O_WRONLY, | |
| 24 | 25 | S_IFMT, | |
| 25 | 26 | S_IFREG | |
| 26 | - } = internalBinding('constants').fs; | ||
| 27 | + } = constants; | ||
| 28 | + | ||
| 27 | 29 | const binding = internalBinding('fs'); | |
| 28 | 30 | const { Buffer } = require('buffer'); | |
| 29 | 31 | ||
@@ -899,6 +901,7 @@ module.exports = { | |||
| 899 | 901 | appendFile, | |
| 900 | 902 | readFile, | |
| 901 | 903 | watch, | |
| 904 | + constants, | ||
| 902 | 905 | }, | |
| 903 | 906 | ||
| 904 | 907 | FileHandle, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,5 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | require('../common'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | + const fs = require('fs'); | ||
| 6 | + const fsPromises = require('fs/promises'); | ||
| 5 | 7 | ||
| 6 | - assert.strictEqual(require('fs/promises'), require('fs').promises); | ||
| 8 | + assert.strictEqual(fsPromises, fs.promises); | ||
| 9 | + assert.strictEqual(fsPromises.constants, fs.constants); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments