filehandle.readFile(options)


  • options <Object> | <string>
  • 返回: <Promise> 成功读取时将使用文件内容履行。 如果未指定编码(使用 options.encoding),则数据作为 <Buffer> 对象返回。 否则,数据将为字符串。

异步地读取文件的全部内容。

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

<FileHandle> 必须支持读取。

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

  • options <Object> | <string>
  • Returns: <Promise> Fulfills upon a successful read with the contents of the file. If no encoding is specified (using options.encoding), the data is returned as a <Buffer> object. Otherwise, the data will be a string.

Asynchronously reads the entire contents of a file.

If options is a string, then it specifies the encoding.

The <FileHandle> has to support reading.

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