filehandle.writeFile(data, options)


异步地将数据写入文件,如果文件已经存在,则替换该文件。 data 可以是字符串、缓冲区、<AsyncIterable>、或 <Iterable> 对象。 成功时不带参数解决 promise。

如果 options 是字符串,则它指定 encoding

<FileHandle> 必须支持写入。

在同一文件上多次使用 filehandle.writeFile() 而不等待 promise 被解决(或拒绝)是不安全的。

如果在文件句柄上进行了一次或多次 filehandle.write() 调用,然后进行 filehandle.writeFile() 调用,则数据将从当前位置写入,直到文件末尾。 它并不总是从文件的开头写入。

Asynchronously writes data to a file, replacing the file if it already exists. data can be a string, a buffer, an <AsyncIterable> or <Iterable> object. The promise is resolved 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 filehandle.writeFile() multiple times on the same file without waiting for the promise to be resolved (or rejected).

If one or more filehandle.write() calls are made on a file handle and then a filehandle.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.