-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
Description
Affected URL(s)
https://nodejs.org/api/fs.html#fsreadfd-buffer-offset-length-position-callback
Description of the problem
It is not clear from Node's fs.read() docs, whether the length argument indicates the maximum number of bytes that Node will attempt to read from the kernel, or whether Node will return exactly length bytes (possibly making multiple read syscalls in the process).
Ie: if I call fs.read() with length = 10, which of these holds:
- When reading a file that is 9 bytes long, exactly 9 bytes are read and
bytesReadis set to 9. - When reading a file that is 9 bytes long, the callback is called with an error because EOF was encountered before the buffer could be filled.
- When reading a file that is 11 bytes long, exactly 10 bytes are read and
bytesReadis set to 10. - When reading a file that is 11 bytes long, but the file is on a slow network filesystem that only reads in chunks of 5 bytes per second, 5 bytes are read and
bytesReadis set to 5.
This is an important thing to document because it determines whether you need to wrap the read call in a loop (like the Linux syscall) if you need a minimum amount of bytes, or whether you do not have to do this.
kylo5aby and tcd
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.