Skip to content
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.read documentation does not specify how to detect EOF condition #35363

Closed
joepie91 opened this issue Sep 26, 2020 · 1 comment · Fixed by #35445
Closed

fs.read documentation does not specify how to detect EOF condition #35363

joepie91 opened this issue Sep 26, 2020 · 1 comment · Fixed by #35445
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.

Comments

@joepie91
Copy link
Contributor

joepie91 commented Sep 26, 2020

As far as I can tell, neither fs.read nor FileHandle#read specify how to detect when the end of a file has been reached, nor can I find this information elsewhere in the fs documentation.

The fs.createReadStream implementation suggests that the answer to this question is "when bytesRead is 0", but this should be added to the documentation if that is indeed the correct way to detect this condition.

@ChALkeR ChALkeR added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Sep 26, 2020
@bnoordhuis
Copy link
Member

The docs probably implicitly assume familiarity with man 2 read but to not keep you in suspense any longer: you detect it by observing a short read (fewer bytes than you requested, possibly zero) but, caveat emptor, the next read can return more bytes if the file was modified concurrently.

Documentation pull request welcome.

@lpinca lpinca closed this as completed in 0f9170e Oct 4, 2020
danielleadams pushed a commit that referenced this issue Oct 6, 2020
Specify how to detect end-of-file when using `fs.read()` and
`filehandle.read()`.

PR-URL: #35445
Fixes: #35363
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
joesepi pushed a commit to joesepi/node that referenced this issue Jan 8, 2021
Specify how to detect end-of-file when using `fs.read()` and
`filehandle.read()`.

PR-URL: nodejs#35445
Fixes: nodejs#35363
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants