Skip to content

Commit 7108893

Browse files
committed
doc: clarify fs.write[Sync]() descriptions
1. All default values for optional `encoding` parameters were documented except for the one in `fs.write(fd, string...)` method. This PR makes up this deficiency. 2. We have two variants of `fs.write()` / `fs.writeSync()` methods: for buffers and strings. Currently, the sync methods have only one common reference to the full description of async methods. However, the link may seem to belong to the last sync variant only (for strings) and, as it refers to the first async variant (for buffers), this may be confusing. This PR makes two different sync variants refer to two different async variants. 3. In passing, both returned values of sync methods were also made more concise and unambiguous. PR-URL: #22402 Refs: https://github.com/nodejs/node/blob/a04f2f7df630427bf869b1e04040975b752973b6/lib/fs.js#L549 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 14e6274 commit 7108893

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

doc/api/fs.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,7 +3422,7 @@ changes:
34223422
* `fd` {integer}
34233423
* `string` {string}
34243424
* `position` {integer}
3425-
* `encoding` {string}
3425+
* `encoding` {string} **Default:** `'utf8'`
34263426
* `callback` {Function}
34273427
* `err` {Error}
34283428
* `written` {integer}
@@ -3548,7 +3548,10 @@ changes:
35483548
* `offset` {integer}
35493549
* `length` {integer}
35503550
* `position` {integer}
3551-
* Returns: {number}
3551+
* Returns: {number} The number of bytes written.
3552+
3553+
For detailed information, see the documentation of the asynchronous version of
3554+
this API: [`fs.write(fd, buffer...)`][].
35523555

35533556
## fs.writeSync(fd, string[, position[, encoding]])
35543557
<!-- YAML
@@ -3563,12 +3566,10 @@ changes:
35633566
* `string` {string}
35643567
* `position` {integer}
35653568
* `encoding` {string}
3566-
* Returns: {number}
3567-
3568-
Returns the number of bytes written.
3569+
* Returns: {number} The number of bytes written.
35693570

35703571
For detailed information, see the documentation of the asynchronous version of
3571-
this API: [`fs.write()`][].
3572+
this API: [`fs.write(fd, string...)`][].
35723573

35733574
## fs Promises API
35743575

@@ -4757,7 +4758,8 @@ the file contents.
47574758
[`fs.symlink()`]: #fs_fs_symlink_target_path_type_callback
47584759
[`fs.utimes()`]: #fs_fs_utimes_path_atime_mtime_callback
47594760
[`fs.watch()`]: #fs_fs_watch_filename_options_listener
4760-
[`fs.write()`]: #fs_fs_write_fd_buffer_offset_length_position_callback
4761+
[`fs.write(fd, buffer...)`]: #fs_fs_write_fd_buffer_offset_length_position_callback
4762+
[`fs.write(fd, string...)`]: #fs_fs_write_fd_string_position_encoding_callback
47614763
[`fs.writeFile()`]: #fs_fs_writefile_file_data_options_callback
47624764
[`inotify(7)`]: http://man7.org/linux/man-pages/man7/inotify.7.html
47634765
[`kqueue(2)`]: https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2

0 commit comments

Comments
 (0)