Repository navigation
What does fs.read's length argument indicate? #52447
Copy link
Copy link
Closed
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
Description
Activity
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Apr 10, 2024 - changed the title
[-]What does `fs.read`'s `length` property indicate?[/-][+]What does `fs.read`'s `length` argument indicate?[/+]on Apr 10, 2024 - addedfsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.
on Apr 10, 2024 @nodejs/fs
- no.
bytesReadcan be lower for any sort of reason. - no
- no,
bytesReadcan be lower - yes
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.
Yes, you need to loop.
It's equivalent ofpreadv2https://man7.org/linux/man-pages/man2/preadv.2.html.Reacted by Mert Can Altin- no.
Great - thank you, this matches my expectation. Do you want to keep this issue open to track updates of the docs or shall I close it?
- addedgood first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
on Apr 10, 2024 I think we should keep it open so that someone improves the doc to avoid confusing future readers.
Reacted by Luca Casonato, Mert Can Altin and Jacob StørdahlReacted by Mert Can Altinis it still open , can i still contribute ?
@joyeecheung#52453 was merged, so I guess this can be closed.
Reacted by Jason khongwir
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
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 thelengthargument indicates the maximum number of bytes that Node will attempt to read from the kernel, or whether Node will return exactlylengthbytes (possibly making multiplereadsyscalls in the process).Ie: if I call
fs.read()with length = 10, which of these holds:bytesReadis set to 9.bytesReadis set to 10.bytesReadis set to 5.This is an important thing to document because it determines whether you need to wrap the
readcall in a loop (like the Linux syscall) if you need a minimum amount of bytes, or whether you do not have to do this.