* Reads a file. * @param {string} path The file path * @param {object|string} [options] Options or encoding * @returns {Promise }
(path, options)
| 244 | * @returns {Promise<Buffer|string>} |
| 245 | */ |
| 246 | async readFile(path, options) { |
| 247 | const flag = (typeof options === 'object' && options !== null) ? |
| 248 | (options.flag ?? 'r') : 'r'; |
| 249 | const handle = await this.open(path, flag); |
| 250 | try { |
| 251 | return await handle.readFile(options); |
| 252 | } finally { |
| 253 | await handle.close(); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Reads a file synchronously. |