fs: support caller-supplied readFile() buffers#63634
Conversation
PR-URL: nodejs#63634 Signed-off-by: Matteo Collina <hello@matteocollina.com>
50d050d to
e04e121
Compare
PR-URL: nodejs#63634 Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
e04e121 to
2f1e60f
Compare
| * `buffer` {Buffer|TypedArray|DataView} A buffer to read into. | ||
| * `getBuffer` {Function} A synchronous function called with the file size and | ||
| returning the buffer to read into. |
There was a problem hiding this comment.
Could we not consolidate these two? Plenty of places across the API surface have options with "either a thing or a thing-like function" types.
There was a problem hiding this comment.
Agreed. It should be quite cheap to check typeof options.buffer === 'function' at the start.
| } | ||
| }); | ||
|
|
||
| const validateReadFileBufferOptions = hideStackFrames((options) => { |
There was a problem hiding this comment.
I would personally advocate for this to throw if both buffer and encoding are provided – directly contradictory patterns should fail validation.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63634 +/- ##
==========================================
+ Coverage 90.29% 90.35% +0.06%
==========================================
Files 730 732 +2
Lines 234782 236689 +1907
Branches 43953 44582 +629
==========================================
+ Hits 211993 213862 +1869
- Misses 14501 14561 +60
+ Partials 8288 8266 -22
🚀 New features to boost your workflow:
|
PR-URL: nodejs#63634 Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
2f1e60f to
e8edd28
Compare
- Remove getBuffer deprecation check from validateReadFileBufferOptions (getBuffer was never released, dead code) - Simplify buffer validation using isArrayBufferView check - Consolidate buffer option description in docs: 'synchronous function called with the file size and returning the buffer to read into' -> 'function called with the file size that returns the buffer' - Add examples for pre-allocated buffer and function variants Co-authored-by: LiviaMedeiros <livia@example.com> Co-authored-by: Renegade334 <renegade334@example.com> Co-authored-by: MattiasBuelens <mattias@example.com> Co-authored-by: jasnell <jasnell@example.com> PR-URL: nodejs#63634 Signed-off-by: Matteo Collina <hello@matteocollina.com>
The getBuffer validation was removed from validateReadFileBufferOptions since getBuffer was never released. Remove the test cases that expected ERR_INVALID_ARG_VALUE for getBuffer. PR-URL: nodejs#63634 Signed-off-by: matteo <matteo@example.com>
PR-URL: nodejs#63634 Signed-off-by: matteo <matteo@example.com>
Commit Queue failed- Loading data for nodejs/node/pull/63634 ✔ Done loading data for nodejs/node/pull/63634 ----------------------------------- PR info ------------------------------------ Title fs: support caller-supplied readFile() buffers (#63634) Author Matteo Collina <matteo.collina@gmail.com> (@mcollina) Branch mcollina:fs-readfile-buffer-option -> nodejs:main Labels fs, semver-minor, needs-ci Commits 4 - fs: support caller-supplied readFile() buffers - fs: address PR review comments - test: remove getBuffer tests - doc: add Buffer import to examples to satisfy lint Committers 1 - Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/63634 Fixes: https://github.com/nodejs/node/issues/63600 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/63634 Fixes: https://github.com/nodejs/node/issues/63600 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> -------------------------------------------------------------------------------- ℹ This PR was created on Fri, 29 May 2026 08:22:28 GMT ✔ Approvals: 3 ✔ - Paolo Insogna (@ShogunPanda) (TSC): https://github.com/nodejs/node/pull/63634#pullrequestreview-4478094154 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/63634#pullrequestreview-4398614605 ✔ - LiviaMedeiros (@LiviaMedeiros): https://github.com/nodejs/node/pull/63634#pullrequestreview-4478938701 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-06-12T05:53:54Z: https://ci.nodejs.org/job/node-test-pull-request/74067/ - Querying data for job/node-test-pull-request/74067/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 63634 From https://github.com/nodejs/node * branch refs/pull/63634/merge -> FETCH_HEAD ✔ Fetched commits as 4383f67279f2..e6c1949c90e7 -------------------------------------------------------------------------------- Auto-merging lib/fs.js Auto-merging lib/internal/fs/promises.js Auto-merging lib/internal/fs/utils.js [main aabbda3359] fs: support caller-supplied readFile() buffers Author: Matteo Collina <hello@matteocollina.com> Date: Fri May 29 10:20:46 2026 +0200 7 files changed, 635 insertions(+), 18 deletions(-) create mode 100644 test/parallel/test-fs-promises-readfile-buffer-option.js create mode 100644 test/parallel/test-fs-readfile-buffer-option.js Auto-merging lib/internal/fs/utils.js [main a395990cbd] fs: address PR review comments Author: Matteo Collina <hello@matteocollina.com> Date: Wed Jun 10 13:14:54 2026 +0000 2 files changed, 88 insertions(+), 22 deletions(-) [main 5386f6d85d] test: remove getBuffer tests Author: Matteo Collina <hello@matteocollina.com> Date: Wed Jun 10 13:42:35 2026 +0000 2 files changed, 12 deletions(-) [main 928677a24f] doc: add Buffer import to examples to satisfy lint Author: Matteo Collina <hello@matteocollina.com> Date: Wed Jun 10 16:15:07 2026 +0000 1 file changed, 6 insertions(+) ✔ Patches applied There are 4 commits in the PR. Attempting autorebase. (node:478) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. (Use `node --trace-deprecation ...` to show where the warning was created) Rebasing (2/8) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- fs: support caller-supplied readFile() buffers
Co-authored-by: LiviaMedeiros <livia@example.com> Signed-off-by: Matteo Collina <hello@matteocollina.com>
|
|
Landed in de67c5c |
Fixes: #63600