@@ -696,11 +696,18 @@ close the `FileHandle` automatically. User code must still call the
696696
697697<!-- YAML
698698added: v10.0.0
699+ changes:
700+ - version: REPLACEME
701+ pr-url: https://github.com/nodejs/node/pull/63634
702+ description: Added support for the ` buffer` option.
699703-->
700704
701705* ` options` {Object|string}
702706 * ` encoding` {string|null} **Default:** ` null `
703707 * ` signal` {AbortSignal} allows aborting an in-progress readFile
708+ * ` buffer` {Buffer|TypedArray|DataView|Function} A buffer to read into, or a
709+ synchronous function called with the file size and returning the buffer to
710+ read into.
704711* Returns: {Promise} Fulfills upon a successful read with the contents of the
705712 file. If no encoding is specified (using ` options .encoding ` ), the data is
706713 returned as a {Buffer} object. Otherwise, the data will be a string.
@@ -709,6 +716,11 @@ Asynchronously reads the entire contents of a file.
709716
710717If ` options` is a string, then it specifies the ` encoding` .
711718
719+ If ` buffer` is provided and no encoding is specified, the returned {Buffer} is
720+ a view over the supplied buffer containing only the bytes read. If the
721+ supplied buffer is too small to contain the entire file, the operation will
722+ fail.
723+
712724The {FileHandle} has to support reading.
713725
714726If one or more ` filehandle .read ()` calls are made on a file handle and then a
@@ -1765,6 +1777,9 @@ try {
17651777<!-- YAML
17661778added: v10.0.0
17671779changes:
1780+ - version: REPLACEME
1781+ pr-url: https://github.com/nodejs/node/pull/63634
1782+ description: Added support for the `buffer` option.
17681783 - version:
17691784 - v15.2.0
17701785 - v14.17.0
@@ -1778,6 +1793,9 @@ changes:
17781793 * `encoding` {string|null} **Default:** `null`
17791794 * `flag` {string} See [support of file system `flags`][]. **Default:** `'r'`.
17801795 * `signal` {AbortSignal} allows aborting an in-progress readFile
1796+ * `buffer` {Buffer|TypedArray|DataView|Function} A buffer to read into, or a
1797+ synchronous function called with the file size and returning the buffer to
1798+ read into.
17811799* Returns: {Promise} Fulfills with the contents of the file.
17821800
17831801Asynchronously reads the entire contents of a file.
@@ -1787,6 +1805,11 @@ as a {Buffer} object. Otherwise, the data will be a string.
17871805
17881806If `options` is a string, then it specifies the encoding.
17891807
1808+ If `buffer` is provided and no encoding is specified, the returned {Buffer} is
1809+ a view over the supplied buffer containing only the bytes read. If the
1810+ supplied buffer is too small to contain the entire file, the promise will be
1811+ rejected.
1812+
17901813When the `path` is a directory, the behavior of `fsPromises.readFile()` is
17911814platform-specific. On macOS, Linux, and Windows, the promise will be rejected
17921815with an error. On FreeBSD, a representation of the directory's contents will be
@@ -4225,6 +4248,9 @@ If `options.withFileTypes` is set to `true`, the `files` array will contain
42254248<!-- YAML
42264249added: v0.1.29
42274250changes:
4251+ - version: REPLACEME
4252+ pr-url: https://github.com/nodejs/node/pull/63634
4253+ description: Added support for the ` buffer` option.
42284254 - version: v18.0.0
42294255 pr-url: https://github.com/nodejs/node/pull/41678
42304256 description: Passing an invalid callback to the ` callback` argument
@@ -4266,6 +4292,9 @@ changes:
42664292 * ` encoding` {string|null} **Default:** ` null `
42674293 * ` flag` {string} See [support of file system ` flags` ][]. **Default:** ` ' r' ` .
42684294 * ` signal` {AbortSignal} allows aborting an in-progress readFile
4295+ * ` buffer` {Buffer|TypedArray|DataView|Function} A buffer to read into, or a
4296+ synchronous function called with the file size and returning the buffer to
4297+ read into.
42694298* ` callback` {Function}
42704299 * ` err` {Error|AggregateError}
42714300 * ` data` {string|Buffer}
@@ -4286,6 +4315,11 @@ contents of the file.
42864315
42874316If no encoding is specified, then the raw buffer is returned.
42884317
4318+ If ` buffer` is provided and no encoding is specified, the returned {Buffer} is
4319+ a view over the supplied buffer containing only the bytes read. If the
4320+ supplied buffer is too small to contain the entire file, the callback is
4321+ called with an error.
4322+
42894323If ` options` is a string, then it specifies the encoding:
42904324
42914325` ` ` mjs
@@ -6428,6 +6462,9 @@ If `options.withFileTypes` is set to `true`, the result will contain
64286462<!-- YAML
64296463added: v0.1.8
64306464changes:
6465+ - version: REPLACEME
6466+ pr-url: https://github.com/nodejs/node/pull/63634
6467+ description: Added support for the ` buffer` option.
64316468 - version: v7.6.0
64326469 pr-url: https://github.com/nodejs/node/pull/10739
64336470 description: The ` path` parameter can be a WHATWG ` URL ` object using ` file: `
@@ -6441,6 +6478,9 @@ changes:
64416478* ` options` {Object|string}
64426479 * ` encoding` {string|null} **Default:** ` null `
64436480 * ` flag` {string} See [support of file system ` flags` ][]. **Default:** ` ' r' ` .
6481+ * ` buffer` {Buffer|TypedArray|DataView|Function} A buffer to read into, or a
6482+ synchronous function called with the file size and returning the buffer to
6483+ read into.
64446484* Returns: {string|Buffer}
64456485
64466486Returns the contents of the ` path` .
@@ -6451,6 +6491,11 @@ this API: [`fs.readFile()`][].
64516491If the ` encoding` option is specified then this function returns a
64526492string. Otherwise it returns a buffer.
64536493
6494+ If ` buffer` is provided and no encoding is specified, the returned {Buffer} is
6495+ a view over the supplied buffer containing only the bytes read. If the
6496+ supplied buffer is too small to contain the entire file, an error will be
6497+ thrown.
6498+
64546499Similar to [` fs .readFile ()` ][], when the path is a directory, the behavior of
64556500` fs .readFileSync ()` is platform-specific.
64566501
0 commit comments