-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: support special files in promises.readFile #21497
Conversation
lib/internal/fs/promises.js
Outdated
if (size > kMaxLength) | ||
throw new ERR_FS_FILE_TOO_LARGE(size); | ||
|
||
const chunks = []; | ||
const chunkSize = Math.min(size, 16384); | ||
let totalRead = 0; | ||
const chunkSize = size === 0 ? 16384 : Math.min(size, 16384); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might wanna factor that number out into a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -125,6 +125,10 @@ async function writeFileHandle(filehandle, data, options) { | |||
} while (remaining > 0); | |||
} | |||
|
|||
// Note: This is different from kReadFileBufferLength used for non-promisified | |||
// fs.readFile. | |||
const kReadFileMaxChunkSize = 16384; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, is there context for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, it was there when I found it so I kept it that way. I just thought it was interesting to note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we'd have to ask @jasnell about it.
CI: https://ci.nodejs.org/job/node-test-pull-request/15726/ (linuxone passes after re-run) |
PR-URL: #21497 Fixes: #21331 Refs: http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html Refs: https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Landed in 5057dd4. |
PR-URL: #21497 Fixes: #21331 Refs: http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html Refs: https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
A size of 0 may indicate that the file is a Linux special file, which may still have content when
read()
. Instead of returning early, use the same approach asfs.readFile()
:node/lib/internal/fs/read_file_context.js
Lines 74 to 88 in 6ced651
Additionally, only the return code of 0 indicates end of file, and we should not use
bytesRead !== chunkSize
as a indication of EOF. Per POSIX:Refs: http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
Refs: https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0
Fixes: #21331
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes