Skip to main content

write

method promises.FileHandle.write
Jump to headingFileHandle.write<TBuffer extends Uint8Array>(
buffer: TBuffer,
offset?: number | null,
length?: number | null,
position?: number | null,
): Promise<{ bytesWritten: number; buffer: TBuffer; }>

Write buffer to the file.

The promise is fulfilled with an object containing two properties:

It is unsafe to use filehandle.write() multiple times on the same file without waiting for the promise to be fulfilled (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.

Type Parameters Jump to heading

Jump to headingTBuffer extends Uint8Array

Parameters Jump to heading

optional
Jump to headingoffset: number | null

The start position from within buffer where the data to write begins.

optional
Jump to headinglength: number | null = buffer.byteLength - offset

The number of bytes from buffer to write.

optional
Jump to headingposition: number | null = 'null'

The offset from the beginning of the file where the data from buffer should be written. If position is not a number, the data will be written at the current position. See the POSIX pwrite(2) documentation for more detail.

Return Type Jump to heading

Promise<{ bytesWritten: number; buffer: TBuffer; }>
Jump to headingFileHandle.write(
data: string,
position?: number | null,
encoding?: BufferEncoding | null,
): Promise<{ bytesWritten: number; buffer: string; }>

Parameters Jump to heading

Jump to headingdata: string
optional
Jump to headingposition: number | null
optional
Jump to headingencoding: BufferEncoding | null

Return Type Jump to heading

Promise<{ bytesWritten: number; buffer: string; }>
Back to top