filehandle.write(buffer, offset[, length[, position]])
将 buffer
写入文件。
buffer
<Buffer> | <TypedArray> | <DataView>offset
<integer> The start position from withinbuffer
where the data to write begins.length
<integer> The number of bytes frombuffer
to write. Default:buffer.byteLength - offset
position
<integer> | <null> The offset from the beginning of the file where the data frombuffer
should be written. Ifposition
is not anumber
, the data will be written at the current position. See the POSIXpwrite(2)
documentation for more detail. Default:null
- Returns: <Promise>
Write buffer
to the file.
The promise is resolved with an object containing two properties:
bytesWritten
<integer> the number of bytes writtenbuffer
<Buffer> | <TypedArray> | <DataView> a reference to thebuffer
written.
It is unsafe to use filehandle.write()
multiple times on the same file
without waiting for the promise to be resolved (or rejected). For this
scenario, use filehandle.createWriteStream()
.
On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.