Skip to content

Commit a499db7

Browse files
Dara Hayesrvagg
Dara Hayes
authored andcommitted
doc: add filehandle.write(string[, position[, encoding]])
Add missing docs for filehandle.write(string[, position[, encoding]]) In the fs.promises API. Fixes: #20406 PR-URL: #23224 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent e9abf42 commit a499db7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

doc/api/fs.md

+31
Original file line numberDiff line numberDiff line change
@@ -3968,6 +3968,37 @@ On Linux, positional writes do not work when the file is opened in append mode.
39683968
The kernel ignores the position argument and always appends the data to
39693969
the end of the file.
39703970

3971+
#### filehandle.write(string[, position[, encoding]])
3972+
<!-- YAML
3973+
added: v10.0.0
3974+
-->
3975+
3976+
* `string` {string}
3977+
* `position` {integer}
3978+
* `encoding` {string} **Default:** `'utf8'`
3979+
* Returns: {Promise}
3980+
3981+
Write `string` to the file. If `string` is not a string, then
3982+
the value will be coerced to one.
3983+
3984+
The `Promise` is resolved with an object containing a `bytesWritten` property
3985+
identifying the number of bytes written, and a `buffer` property containing
3986+
a reference to the `string` written.
3987+
3988+
`position` refers to the offset from the beginning of the file where this data
3989+
should be written. If the type of `position` is not a `number` the data
3990+
will be written at the current position. See pwrite(2).
3991+
3992+
`encoding` is the expected string encoding.
3993+
3994+
It is unsafe to use `filehandle.write()` multiple times on the same file
3995+
without waiting for the `Promise` to be resolved (or rejected). For this
3996+
scenario, [`fs.createWriteStream()`][] is strongly recommended.
3997+
3998+
On Linux, positional writes do not work when the file is opened in append mode.
3999+
The kernel ignores the position argument and always appends the data to
4000+
the end of the file.
4001+
39714002
#### filehandle.writeFile(data, options)
39724003
<!-- YAML
39734004
added: v10.0.0

0 commit comments

Comments
 (0)