filehandle.writeFile(data, options)
data<string> | <Buffer> | <TypedArray> | <DataView> | <AsyncIterable> | <Iterable> | <Stream>options<Object> | <string>- 返回:<Promise>
异步地将数据写入文件,如果文件已存在则替换它。data 可以是字符串、缓冲区、<AsyncIterable> 或 <Iterable> 对象。操作成功时,Promise 将不带任何参数地完成。
【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.】
如果 options 是一个字符串,那么它指定了 encoding。
【If options is a string, then it specifies the encoding.】
<FileHandle> 必须支持写入。
【The <FileHandle> has to support writing.】
在同一个文件上多次使用 filehandle.writeFile() 是不安全的,除非等待该 promise 被完成(或拒绝)。
【It is unsafe to use filehandle.writeFile() multiple times on the same file
without waiting for the promise to be fulfilled (or rejected).】
如果对文件句柄执行一次或多次 filehandle.write() 调用,然后再进行 filehandle.writeFile() 调用,数据将从当前位置写入到文件末尾。它并不总是从文件开头写入。
【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.】