Skip to content

Commit 8bc4de6

Browse files
author
Dara Hayes
committed
doc: add filehandle.write(string[, position[, encoding]])
Add missing docs for filehandle.write(string[, position[, encoding]]) In the fs.promises API. fixes: #20406
1 parent 98819df commit 8bc4de6

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

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

0 commit comments

Comments
 (0)