fs.readFile(path[, options], callback)
path<string> | <Buffer> | <URL> | <integer> 文件名或文件描述符options<Object> | <string>encoding<string> | <null> 默认值:nullflag<string> 请参阅对文件系统flags的支持。 默认值:'r'。
callback<Function>
异步地读取文件的全部内容。
fs.readFile('/etc/passwd', (err, data) => {
  if (err) throw err;
  console.log(data);
});回调传入了两个参数 (err, data),其中 data 是文件的内容。
如果未指定编码,则返回原始缓冲区。
如果 options 是字符串,则它指定编码:
fs.readFile('/etc/passwd', 'utf8', callback);当路径是目录时,fs.readFile() 和 fs.readFileSync() 的行为是特定于平台的。
在 macOS、Linux 和 Windows 上,将返回错误。
在 FreeBSD 上,将返回目录内容的表示。
// macOS、Linux 和 Windows
fs.readFile('<directory>', (err, data) => {
  // => [Error: EISDIR: illegal operation on a directory, read <directory>]
});
//  FreeBSD
fs.readFile('<directory>', (err, data) => {
  // => null, <data>
});fs.readFile() 函数缓冲整个文件。
为了最小化内存成本,在可能的情况下优先通过 fs.createReadStream() 进行流式传输。
path<string> | <Buffer> | <URL> | <integer> filename or file descriptoroptions<Object> | <string>encoding<string> | <null> Default:nullflag<string> See support of file systemflags. Default:'r'.
callback<Function>
Asynchronously reads the entire contents of a file.
fs.readFile('/etc/passwd', (err, data) => {
  if (err) throw err;
  console.log(data);
});The callback is passed two arguments (err, data), where data is the
contents of the file.
If no encoding is specified, then the raw buffer is returned.
If options is a string, then it specifies the encoding:
fs.readFile('/etc/passwd', 'utf8', callback);When the path is a directory, the behavior of fs.readFile() and
fs.readFileSync() is platform-specific. On macOS, Linux, and Windows, an
error will be returned. On FreeBSD, a representation of the directory's contents
will be returned.
// macOS, Linux, and Windows
fs.readFile('<directory>', (err, data) => {
  // => [Error: EISDIR: illegal operation on a directory, read <directory>]
});
//  FreeBSD
fs.readFile('<directory>', (err, data) => {
  // => null, <data>
});The fs.readFile() function buffers the entire file. To minimize memory costs,
when possible prefer streaming via fs.createReadStream().