Skip to content

Commit 492e2a4

Browse files
Dara Hayescodebytere
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 <[email protected]>
1 parent 94553b2 commit 492e2a4

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
@@ -3941,6 +3941,37 @@ On Linux, positional writes do not work when the file is opened in append mode.
39413941
The kernel ignores the position argument and always appends the data to
39423942
the end of the file.
39433943

3944+
#### filehandle.write(string[, position[, encoding]])
3945+
<!-- YAML
3946+
added: v10.0.0
3947+
-->
3948+
3949+
* `string` {string}
3950+
* `position` {integer}
3951+
* `encoding` {string} **Default:** `'utf8'`
3952+
* Returns: {Promise}
3953+
3954+
Write `string` to the file. If `string` is not a string, then
3955+
the value will be coerced to one.
3956+
3957+
The `Promise` is resolved with an object containing a `bytesWritten` property
3958+
identifying the number of bytes written, and a `buffer` property containing
3959+
a reference to the `string` written.
3960+
3961+
`position` refers to the offset from the beginning of the file where this data
3962+
should be written. If the type of `position` is not a `number` the data
3963+
will be written at the current position. See pwrite(2).
3964+
3965+
`encoding` is the expected string encoding.
3966+
3967+
It is unsafe to use `filehandle.write()` multiple times on the same file
3968+
without waiting for the `Promise` to be resolved (or rejected). For this
3969+
scenario, [`fs.createWriteStream()`][] is strongly recommended.
3970+
3971+
On Linux, positional writes do not work when the file is opened in append mode.
3972+
The kernel ignores the position argument and always appends the data to
3973+
the end of the file.
3974+
39443975
#### filehandle.writeFile(data, options)
39453976
<!-- YAML
39463977
added: v10.0.0

0 commit comments

Comments
 (0)