-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature-request - add [lazy] option parents
to fs.writeFile[Sync], fs.appendFile[Sync], fs.open[Sync]
#35775
base: main
Are you sure you want to change the base?
Changes from 1 commit
87f66f2
eacc195
a78c1e2
528331a
480eaf7
ae1a6cf
b006217
9129c42
b967e5c
43c2b6f
a132adb
ca8deb8
7b5b3e1
47dbc40
8bd103b
229c4e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1354,6 +1354,9 @@ try { | |
<!-- YAML | ||
added: v0.6.7 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
- version: v10.0.0 | ||
pr-url: https://github.com/nodejs/node/pull/12562 | ||
description: The `callback` parameter is no longer optional. Not passing | ||
|
@@ -1376,6 +1379,8 @@ changes: | |
* `encoding` {string|null} **Default:** `'utf8'` | ||
* `mode` {integer} **Default:** `0o666` | ||
* `flag` {string} See [support of file system `flags`][]. **Default:** `'a'`. | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
* `callback` {Function} | ||
* `err` {Error} | ||
|
||
|
@@ -1415,6 +1420,9 @@ fs.open('message.txt', 'a', (err, fd) => { | |
<!-- YAML | ||
added: v0.6.7 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
- version: v7.0.0 | ||
pr-url: https://github.com/nodejs/node/pull/7831 | ||
description: The passed `options` object will never be modified. | ||
|
@@ -1429,6 +1437,8 @@ changes: | |
* `encoding` {string|null} **Default:** `'utf8'` | ||
* `mode` {integer} **Default:** `0o666` | ||
* `flag` {string} See [support of file system `flags`][]. **Default:** `'a'`. | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
|
||
Synchronously append data to a file, creating the file if it does not yet | ||
exist. `data` can be a string or a [`Buffer`][]. | ||
|
@@ -2788,13 +2798,13 @@ this API: [`fs.mkdtemp()`][]. | |
The optional `options` argument can be a string specifying an encoding, or an | ||
object with an `encoding` property specifying the character encoding to use. | ||
|
||
## `fs.open(path[, flags[, mode]], callback)` | ||
## `fs.open(path[, flag[, mode]], callback)` | ||
<!-- YAML | ||
added: v0.0.2 | ||
changes: | ||
- version: v11.1.0 | ||
pr-url: https://github.com/nodejs/node/pull/23767 | ||
description: The `flags` argument is now optional and defaults to `'r'`. | ||
description: The `flag` argument is now optional and defaults to `'r'`. | ||
- version: v9.9.0 | ||
pr-url: https://github.com/nodejs/node/pull/18801 | ||
description: The `as` and `as+` flags are supported now. | ||
|
@@ -2805,7 +2815,7 @@ changes: | |
--> | ||
|
||
* `path` {string|Buffer|URL} | ||
* `flags` {string|number} See [support of file system `flags`][]. | ||
* `flag` {string|number} See [support of file system `flags`][]. | ||
**Default:** `'r'`. | ||
* `mode` {string|integer} **Default:** `0o666` (readable and writable) | ||
* `callback` {Function} | ||
|
@@ -2828,6 +2838,28 @@ a colon, Node.js will open a file system stream, as described by | |
Functions based on `fs.open()` exhibit this behavior as well: | ||
`fs.writeFile()`, `fs.readFile()`, etc. | ||
|
||
## `fs.open(path[, options], callback)` | ||
<!-- YAML | ||
added: REPLACEME | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
--> | ||
|
||
* `path` {string|Buffer|URL} | ||
* `options` {Object|string} | ||
* `flag` {string|number} See [support of file system `flags`][]. | ||
**Default:** `'r'`. | ||
* `mode` {string|integer} **Default:** `0o666` (readable and writable) | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
* `callback` {Function} | ||
* `err` {Error} | ||
* `fd` {integer} | ||
|
||
Asynchronous file open using `options` signature-form. | ||
|
||
## `fs.opendir(path[, options], callback)` | ||
<!-- YAML | ||
added: v12.12.0 | ||
|
@@ -2884,13 +2916,13 @@ and cleaning up the directory. | |
The `encoding` option sets the encoding for the `path` while opening the | ||
directory and subsequent read operations. | ||
|
||
## `fs.openSync(path[, flags, mode])` | ||
## `fs.openSync(path[, flag, mode])` | ||
<!-- YAML | ||
added: v0.1.21 | ||
changes: | ||
- version: v11.1.0 | ||
pr-url: https://github.com/nodejs/node/pull/23767 | ||
description: The `flags` argument is now optional and defaults to `'r'`. | ||
description: The `flag` argument is now optional and defaults to `'r'`. | ||
- version: v9.9.0 | ||
pr-url: https://github.com/nodejs/node/pull/18801 | ||
description: The `as` and `as+` flags are supported now. | ||
|
@@ -2901,7 +2933,7 @@ changes: | |
--> | ||
|
||
* `path` {string|Buffer|URL} | ||
* `flags` {string|number} **Default:** `'r'`. | ||
* `flag` {string|number} **Default:** `'r'`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this changed from flags to flag? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
fs.writeFileSync("aa/bb/cc/dd.txt", {
// do we really want internal monkey-patching from
// `flag` => `flags` when passed to fs.openSync()?
flag: "w+",
parents: true
});
if ppl feel strongly about it, i can revert back to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be reverted from this PR as it's not related with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. k, reverted documentation of |
||
See [support of file system `flags`][]. | ||
* `mode` {string|integer} **Default:** `0o666` | ||
* Returns: {number} | ||
|
@@ -2911,6 +2943,25 @@ Returns an integer representing the file descriptor. | |
For detailed information, see the documentation of the asynchronous version of | ||
this API: [`fs.open()`][]. | ||
|
||
## `fs.openSync(path[, options])` | ||
<!-- YAML | ||
added: REPLACEME | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
--> | ||
|
||
* `path` {string|Buffer|URL} | ||
* `options` {Object|string} | ||
* `flag` {string|number} See [support of file system `flags`][]. | ||
**Default:** `'r'`. | ||
* `mode` {string|integer} **Default:** `0o666` (readable and writable) | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
|
||
Synchronous file open using `options` signature-form. | ||
|
||
## `fs.read(fd, buffer, offset, length, position, callback)` | ||
<!-- YAML | ||
added: v0.0.2 | ||
|
@@ -4415,6 +4466,9 @@ details. | |
<!-- YAML | ||
added: v0.1.29 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
- version: v15.2.0 | ||
pr-url: https://github.com/nodejs/node/pull/35993 | ||
description: The options argument may include an AbortSignal to abort an | ||
|
@@ -4453,6 +4507,8 @@ changes: | |
* `encoding` {string|null} **Default:** `'utf8'` | ||
* `mode` {integer} **Default:** `0o666` | ||
* `flag` {string} See [support of file system `flags`][]. **Default:** `'w'`. | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
* `signal` {AbortSignal} allows aborting an in-progress writeFile | ||
* `callback` {Function} | ||
* `err` {Error} | ||
|
@@ -4537,6 +4593,9 @@ to contain only `', World'`. | |
<!-- YAML | ||
added: v0.1.29 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
- version: v14.12.0 | ||
pr-url: https://github.com/nodejs/node/pull/34993 | ||
description: The `data` parameter will stringify an object with an | ||
|
@@ -4563,6 +4622,8 @@ changes: | |
* `encoding` {string|null} **Default:** `'utf8'` | ||
* `mode` {integer} **Default:** `0o666` | ||
* `flag` {string} See [support of file system `flags`][]. **Default:** `'w'`. | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
|
||
Returns `undefined`. | ||
|
||
|
@@ -5193,6 +5254,10 @@ the error raised if the file is not accessible. | |
### `fsPromises.appendFile(path, data[, options])` | ||
<!-- YAML | ||
added: v10.0.0 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
--> | ||
|
||
* `path` {string|Buffer|URL|FileHandle} filename or `FileHandle` | ||
|
@@ -5201,6 +5266,8 @@ added: v10.0.0 | |
* `encoding` {string|null} **Default:** `'utf8'` | ||
* `mode` {integer} **Default:** `0o666` | ||
* `flag` {string} See [support of file system `flags`][]. **Default:** `'a'`. | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
* Returns: {Promise} | ||
|
||
Asynchronously append data to a file, creating the file if it does not yet | ||
|
@@ -5421,17 +5488,17 @@ characters directly to the `prefix` string. For instance, given a directory | |
`prefix` must end with a trailing platform-specific path separator | ||
(`require('path').sep`). | ||
|
||
### `fsPromises.open(path, flags[, mode])` | ||
### `fsPromises.open(path, flag[, mode])` | ||
<!-- YAML | ||
added: v10.0.0 | ||
changes: | ||
- version: v11.1.0 | ||
pr-url: https://github.com/nodejs/node/pull/23767 | ||
description: The `flags` argument is now optional and defaults to `'r'`. | ||
description: The `flag` argument is now optional and defaults to `'r'`. | ||
--> | ||
|
||
* `path` {string|Buffer|URL} | ||
* `flags` {string|number} See [support of file system `flags`][]. | ||
* `flag` {string|number} See [support of file system `flags`][]. | ||
**Default:** `'r'`. | ||
* `mode` {string|integer} **Default:** `0o666` (readable and writable) | ||
* Returns: {Promise} | ||
|
@@ -5447,6 +5514,25 @@ by [Naming Files, Paths, and Namespaces][]. Under NTFS, if the filename contains | |
a colon, Node.js will open a file system stream, as described by | ||
[this MSDN page][MSDN-Using-Streams]. | ||
|
||
### `fsPromises.open(path[, options])` | ||
<!-- YAML | ||
added: REPLACEME | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
--> | ||
|
||
* `path` {string|Buffer|URL} | ||
* `options` {Object|string} | ||
* `flag` {string|number} See [support of file system `flags`][]. | ||
**Default:** `'r'`. | ||
* `mode` {string|integer} **Default:** `0o666` (readable and writable) | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
|
||
Asynchronous file open that returns a `Promise` using `options` signature-form. | ||
|
||
### `fsPromises.opendir(path[, options])` | ||
<!-- YAML | ||
added: v12.12.0 | ||
|
@@ -5780,6 +5866,9 @@ The `atime` and `mtime` arguments follow these rules: | |
<!-- YAML | ||
added: v10.0.0 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/35775 | ||
description: add option `parents`. | ||
- version: v15.2.0 | ||
pr-url: https://github.com/nodejs/node/pull/35993 | ||
description: The options argument may include an AbortSignal to abort an | ||
|
@@ -5795,11 +5884,13 @@ changes: | |
--> | ||
|
||
* `file` {string|Buffer|URL|FileHandle} filename or `FileHandle` | ||
* `data` {string|Buffer|Uint8Array|Object} | ||
* `data` {string|Buffer|TypedArray|DataView|Object} | ||
* `options` {Object|string} | ||
* `encoding` {string|null} **Default:** `'utf8'` | ||
* `mode` {integer} **Default:** `0o666` | ||
* `flag` {string} See [support of file system `flags`][]. **Default:** `'w'`. | ||
* `parents` {boolean} create parent-directories if they do not exist. | ||
**Default:** `false`. | ||
* `signal` {AbortSignal} allows aborting an in-progress writeFile | ||
* Returns: {Promise} | ||
|
||
|
@@ -6255,7 +6346,7 @@ the file contents. | |
[`fs.lutimes()`]: #fs_fs_lutimes_path_atime_mtime_callback | ||
[`fs.mkdir()`]: #fs_fs_mkdir_path_options_callback | ||
[`fs.mkdtemp()`]: #fs_fs_mkdtemp_prefix_options_callback | ||
[`fs.open()`]: #fs_fs_open_path_flags_mode_callback | ||
[`fs.open()`]: #fs_fs_open_path_flag_mode_callback | ||
[`fs.opendir()`]: #fs_fs_opendir_path_options_callback | ||
[`fs.opendirSync()`]: #fs_fs_opendirsync_path_options | ||
[`fs.read()`]: #fs_fs_read_fd_buffer_offset_length_position_callback | ||
|
@@ -6274,7 +6365,7 @@ the file contents. | |
[`fs.write(fd, string...)`]: #fs_fs_write_fd_string_position_encoding_callback | ||
[`fs.writeFile()`]: #fs_fs_writefile_file_data_options_callback | ||
[`fs.writev()`]: #fs_fs_writev_fd_buffers_position_callback | ||
[`fsPromises.open()`]: #fs_fspromises_open_path_flags_mode | ||
[`fsPromises.open()`]: #fs_fspromises_open_path_flag_mode | ||
[`fsPromises.opendir()`]: #fs_fspromises_opendir_path_options | ||
[`fsPromises.utimes()`]: #fs_fspromises_utimes_path_atime_mtime | ||
[`inotify(7)`]: https://man7.org/linux/man-pages/man7/inotify.7.html | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this changed from flags to flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair, the FS API and documentation already uses those inconsistently (E.G.:
flags
infs.openSync
,flag
infs.readFileSync
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that changing the documentation from
flags
toflag
would break the existing hypertext links (from StackOverflow, blog posts, etc.), which is something we'd rather not do.