writeFile

abstract fun writeFile(path: Value, data: Value): JsPromise<Unit>

Method: fs.writeFile

Asynchronously writes data to a file, replacing the file if it already exists. data can be a string, a buffer, an AsyncIterable, or an Iterable object. The promise is fulfilled with no arguments upon success.

If options is a string, then it specifies the encoding. The FileHandle has to support writing.

It is unsafe to use writeFile multiple times on the same file without waiting for the promise to be fulfilled (or rejected).

If one or more write calls are made on a file handle and then a writeFile call is made, the data will be written from the current position till the end of the file. It doesn't always write from the beginning of the file.

Return

A promise which resolves with no value upon success.

Parameters

path

The path to the file to write.

data

The data to write to the file.


abstract fun writeFile(path: Value, data: Value, options: Value?): JsPromise<Unit>
abstract fun writeFile(path: Path, data: StringOrBuffer, options: WriteFileOptions? = null): JsPromise<Unit>

Method: fs.writeFile

Asynchronously writes data to a file, replacing the file if it already exists. data can be a string, a buffer, an AsyncIterable, or an Iterable object. The promise is fulfilled with no arguments upon success.

If options is a string, then it specifies the encoding. The FileHandle has to support writing.

It is unsafe to use writeFile multiple times on the same file without waiting for the promise to be fulfilled (or rejected).

If one or more write calls are made on a file handle and then a writeFile call is made, the data will be written from the current position till the end of the file. It doesn't always write from the beginning of the file.

Return

A promise which resolves with no value upon success.

Parameters

path

The path to the file to write.

data

The data to write to the file.

options

The options to use for the file write operation.