New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: add read(buffer[, options]) versions #42768
Conversation
This adds the following: `fs.read(fd, buffer[, options], callback)` `filehandle.read(buffer[, options])`
|
Offloaded I'm still confused about
I believe that the intention behind original test was purely about default params (so, for example, it won't override position it default value for it was My personal preference in a context of this PR is to prohibit it to avoid any intersection with |
|
In current state or this PR, breaking changes for If there are still any signs of breaking changes, please do not hesitate to point them out. |
Commit Queue failed- Loading data for nodejs/node/pull/42768 ✔ Done loading data for nodejs/node/pull/42768 ----------------------------------- PR info ------------------------------------ Title fs: add read(buffer[, options]) versions (#42768) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch LiviaMedeiros:optional-read-signature -> nodejs:master Labels fs, semver-minor, author ready, needs-ci, commit-queue-squash Commits 16 - fs: add read(buffer, options) signatures - squash: make offsetOrOptions more consistent - squash: add doc entries - squash: fix fs.read() - squash: expand fs-read-optional test - squash: expand fs-read-promises-optional test - squash: improve tests - squash: fixup - squash: fixup - squash: inline null coalescing - squash: revert changes in fs.readSync() - squash: disallow offset === false - squash: fixup - squash: allow offset === null - squash: fix tests being other way round - squash: adjust tests Committers 1 - LiviaMedeiros PR-URL: https://github.com/nodejs/node/pull/42768 Refs: https://github.com/nodejs/node/pull/42601 Reviewed-By: Antoine du Hamel ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/42768 Refs: https://github.com/nodejs/node/pull/42601 Reviewed-By: Antoine du Hamel -------------------------------------------------------------------------------- ℹ This PR was created on Sun, 17 Apr 2022 17:15:02 GMT ✔ Approvals: 1 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/42768#pullrequestreview-950452626 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2022-04-29T02:55:25Z: https://ci.nodejs.org/job/node-test-pull-request/43764/ - Querying data for job/node-test-pull-request/43764/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/master up to date... From https://github.com/nodejs/node * branch master -> FETCH_HEAD ✔ origin/master is now up-to-date - Downloading patch for 42768 From https://github.com/nodejs/node * branch refs/pull/42768/merge -> FETCH_HEAD ✔ Fetched commits as 916a13a8a36d..ab0b534874af -------------------------------------------------------------------------------- Auto-merging lib/fs.js [master 4b272000d4] fs: add read(buffer, options) signatures Author: LiviaMedeiros Date: Fri Apr 15 22:01:15 2022 +0800 3 files changed, 37 insertions(+), 30 deletions(-) Auto-merging lib/fs.js CONFLICT (content): Merge conflict in lib/fs.js error: could not apply aec64cae9d... squash: make offsetOrOptions more consistent hint: After resolving the conflicts, mark them with hint: "git add/rm ", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". ✖ Failed to apply patcheshttps://github.com/nodejs/node/actions/runs/2259461302 |
|
Rebasing this atm |
|
Landed in 57678e5 |
|
Oh, thanks! |
Notable changes: * Revert_ "deps: add template for generated headers" (Daniel Bevenius) #42978 * deps: upgrade npm to 8.9.0 (npm team) #42968 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (Livia Medeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 PR-URL: TBD
Notable changes: * Revert_ "deps: add template for generated headers" (Daniel Bevenius) #42978 * deps: upgrade npm to 8.9.0 (npm team) #42968 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (Livia Medeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 PR-URL: TBD
Notable changes: * Revert_ "deps: add template for generated headers" (Daniel Bevenius) #42978 * deps: upgrade npm to 8.9.0 (npm team) #42968 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (Livia Medeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 PR-URL: #43036
Notable changes: * Revert_ "deps: add template for generated headers" (Daniel Bevenius) #42978 * deps: upgrade npm to 8.9.0 (npm team) #42968 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (Livia Medeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 PR-URL: #43036
Notable changes: * This release updates OpenSSL to 3.0.3. This update can be treated as a security release as the issues addressed in OpenSSL 3.0.3 slightly affect Node.js 18. See https://nodejs.org/en/blog/vulnerability/openssl-fixes-in-regular-releases-may2022/ for more information on how the May 2022 OpenSSL releases affect other Node.js release lines. * *Revert*_ "deps: add template for generated headers" (Daniel Bevenius) #42978 * deps: update archs files for quictls/openssl-3.0.3+quic (RafaelGSS) #43022 * deps: update undici to 5.2.0 (Node.js GitHub Bot) #43059 * deps: upgrade npm to 8.9.0 (npm team) #42968 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 * deps: upgrade openssl sources to quictls/openssl-3.0.3 (RafaelGSS) #43022 * doc: add LiviaMedeiros to collaborators (LiviaMedeiros) #43039 * doc: add release key for Juan Arboleda (Juan José) #42961 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Paolo Insogna) #42812 * perf_hooks: add PerformanceResourceTiming (RafaelGSS) #42725 PR-URL: #43036
OpenSSL This update can be treated as a security release as the issues addressed in OpenSSL 3.0.3 slightly affect Node.js 18. See https://nodejs.org/en/blog/vulnerability/openssl-fixes-in-regular-releases-may2022/ for more information on how the May 2022 OpenSSL releases affect other Node.js release lines. * deps: update archs files for quictls/openssl-3.0.3+quic (RafaelGSS) #43022 * deps: upgrade openssl sources to quictls/openssl-3.0.3 (RafaelGSS) #43022 Other Notable changes * *Revert*_ "deps: add template for generated headers" (Daniel Bevenius) #42978 * deps: update undici to 5.2.0 (Node.js GitHub Bot) #43059 * deps: upgrade npm to 8.9.0 (npm team) #42968 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 * doc: add LiviaMedeiros to collaborators (LiviaMedeiros) #43039 * doc: add release key for Juan Arboleda (Juan José) #42961 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Paolo Insogna) #42812 * perf_hooks: add PerformanceResourceTiming (RafaelGSS) #42725 PR-URL: #43036
OpenSSL This update can be treated as a security release as the issues addressed in OpenSSL 3.0.3 slightly affect Node.js 18. See https://nodejs.org/en/blog/vulnerability/openssl-fixes-in-regular-releases-may2022/ for more information on how the May 2022 OpenSSL releases affect other Node.js release lines. * deps: update archs files for quictls/openssl-3.0.3+quic (RafaelGSS) #43022 * deps: upgrade openssl sources to quictls/openssl-3.0.3 (RafaelGSS) #43022 Other Notable Changes * *Revert*_ "deps: add template for generated headers" (Daniel Bevenius) #42978 * deps: update undici to 5.2.0 (Node.js GitHub Bot) #43059 * deps: upgrade npm to 8.9.0 (npm team) #42968 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 * doc: add LiviaMedeiros to collaborators (LiviaMedeiros) #43039 * doc: add release key for Juan Arboleda (Juan José) #42961 * (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 * (SEMVER-MINOR) http: added connection closing methods (Paolo Insogna) #42812 * perf_hooks: add PerformanceResourceTiming (RafaelGSS) #42725 PR-URL: #43036
Notable changes: OpenSSL 3.0.3 This update can be treated as a security release as the issues addressed in OpenSSL 3.0.3 slightly affect Node.js 18. See https://nodejs.org/en/blog/vulnerability/openssl-fixes-in-regular-releases-may2022/ for more information on how the May 2022 OpenSSL releases affect other Node.js release lines. - deps: update archs files for quictls/openssl-3.0.3+quic (RafaelGSS) #43022 - deps: upgrade openssl sources to quictls/openssl-3.0.3 (RafaelGSS) #43022 Other notable changes: - _Revert_ "deps: add template for generated headers" (Daniel Bevenius) #42978 - deps: update undici to 5.2.0 (Node.js GitHub Bot) #43059 - deps: upgrade npm to 8.9.0 (npm team) #42968 - (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 - (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 - doc: add LiviaMedeiros to collaborators (LiviaMedeiros) #43039 - doc: add release key for Juan Arboleda (Juan José) #42961 - (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 - (SEMVER-MINOR) http: added connection closing methods (Paolo Insogna) #42812 - (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) #42725 PR-URL: #43036
Notable changes: OpenSSL 3.0.3 This update can be treated as a security release as the issues addressed in OpenSSL 3.0.3 slightly affect Node.js 18. See https://nodejs.org/en/blog/vulnerability/openssl-fixes-in-regular-releases-may2022/ for more information on how the May 2022 OpenSSL releases affect other Node.js release lines. - deps: update archs files for quictls/openssl-3.0.3+quic (RafaelGSS) #43022 - deps: upgrade openssl sources to quictls/openssl-3.0.3 (RafaelGSS) #43022 Other notable changes: - _Revert_ "deps: add template for generated headers" (Daniel Bevenius) #42978 - deps: update undici to 5.2.0 (Node.js GitHub Bot) #43059 - deps: upgrade npm to 8.9.0 (npm team) #42968 - (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 - (SEMVER-MINOR) http: added connection closing methods (Shogun) #42812 - doc: add LiviaMedeiros to collaborators (LiviaMedeiros) #43039 - doc: add release key for Juan Arboleda (Juan José) #42961 - (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) #42768 - (SEMVER-MINOR) http: added connection closing methods (Paolo Insogna) #42812 - (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) #42725 PR-URL: #43036
Refs: #42601 (writing counterparts)
This PR does:
fs.read(fd, buffer[, options], callback)filehandle.read(buffer[, options])Aligning(offloaded due to potential breakage)fs.readSynccode (changes in UB corner cases) 1These changes would allow to:
buffer[, options]signature 2fs.readSynctypechecking 3params4 signatures later, if needed 5paramssignatures later, if strongly needed 6fs.readandfh.readless error-prone 6Why current behaviour is questionable
Default buffer in
fs.readandfilehandle.readisBuffer.alloc(16384). It's a pretty reasonable value for positioned argument (i.e. if it's used only when all further arguments are unset as well), but it's a footgun when length is defined.Without reading the docs properly, I'd totes assume that it allocates
length + offset||0number of bytes by default.Because of that,
bufferhas to be allocated explicitly. Which makes[buffer[, options]]signature more reasonable and less misleading.Footnotes
Changes in UB are about interpreting↩
false/null/undefinedvalues as invalid or default. I think, the best way here is to interprettypeof offsetOrOptions === 'object'as indicator of attempt to use "named params" version. null means default values. false and undefined meansoffset === 0. Everything else goes to offset's integer validation.Exception: Callback API methods will still check the number of arguments as well, to keep
callbackstrictly positioned.Refs: #42601 (comment)↩
Current implementation of↩
fs.readSyncinterprets any value as options object. For example, passing a primitive string will use its length property without any warning.I use the following terminology here:↩
options == { offset, length, position },params == { buffer, ...options } == { buffer, offset, length, position }Theoretical reason to include↩
bufferis its strong connection tooffsetandlength. If we specify nonzero offset, we usually imply a non-arbitrary buffer. However, I don't have strong arguments nor good examples; and it can be worked around anyway.See "Why current behaviour is questionable" foldablie↩ ↩ 2