镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@joepie91

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.

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    fsIssues and PRs related to file-system APIs and the fs module.
    on Sep 26, 2020
  2. bnoordhuis commented on Sep 27, 2020

    @bnoordhuis
    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.

  3. added a commit that references this issue on Oct 6, 2020
  4. added a commit that references this issue on Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions