fs.read(fd, buffer, offset, length, position, callback)

fd 指定的文件中读取数据。

buffer 是数据将写入的缓冲区。

offset 是 buffer 中开始写入的偏移量。

length 是一个整数,指定要读取的字节数。

position 参数指定从文件中开始读取的位置。 如果 positionnull,则从当前文件位置读取数据,并更新文件位置。 如果 position 是整数,则文件位置将保持不变。

回调有三个参数 (err, bytesRead, buffer)

如果调用此方法的 util.promisify() 版本,则返回的 Promise 会返回具有 bytesRead 属性和 buffer 属性的 Object

Read data from the file specified by fd.

buffer is the buffer that the data will be written to.

offset is the offset in the buffer to start writing at.

length is an integer specifying the number of bytes to read.

position is an argument specifying where to begin reading from in the file. If position is null, data will be read from the current file position, and the file position will be updated. If position is an integer, the file position will remain unchanged.

The callback is given the three arguments, (err, bytesRead, buffer).

If this method is invoked as its util.promisify()ed version, it returns a Promise for an Object with bytesRead and buffer properties.