-
Notifications
You must be signed in to change notification settings - Fork 30k
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 at position 0 followed by position null reads wrong data #8397
Comments
What's happening here is that when you specify a position >= 0, |
Should the docs be updated to make this clear? Or would it be useful to On Friday, September 2, 2016, Brian White [email protected] wrote:
|
/cc @nodejs/collaborators |
The documentation for
Node.js has worked this way since forever so I don't think we would want to change that. It's covered by |
I should also note that if you need/want seeking support (to set the file pointer), there are always addons like |
Those are really bad anti-patterns when reading or writing asynchronously because there is no consistent ordering of events. Consider: fs.read(...);
fs.seekSync(...); Does the seek happen before or after the read? No one knows. No one can know. |
@bnoordhuis Sure but if you call What happens when you do: fs.read(fd, buf1, 0, 4, null, ...);
fs.read(fd, buf2, 0, 4, null, ...); ? Is there a defined order in that scenario? |
There isn't, you should use positional reads in that case. |
Disagree. It is unclear for the original example I posted. If you do a read starting at position 0, you then think (rightfully so because nothing tells you otherwise) that the file position is now 0 + N bytes (4 in my example) and that a read using
I don't disagree that this is the better strategy (to be explicit in your read positions in these cases), which is why I think the documentation should make it clearer and guide the developer in understanding that position specified reading is disjoint from null position reading. |
Documentation improvement PR would be welcome. /cc @nodejs/documentation If no one already reading this is inclined to submit a PR, then perhaps it makes sense to put a |
for me something has changed on 8.2 compared to 8.1, the documentation is confusing and #8397 (comment) is correct |
What happen to the file position after a read using a position null or integer was not clear and you can assume that the cursor of the file descriptor is updated even if position is an integer. Fixes: nodejs#8397
What happen to the file position after a read using a position null or integer was not clear and you can assume that the cursor of the file descriptor is updated even if position is an integer. PR-URL: #14631 Fixes: #8397 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
What happen to the file position after a read using a position null or integer was not clear and you can assume that the cursor of the file descriptor is updated even if position is an integer. PR-URL: #14631 Fixes: #8397 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
After reading from position
0
(using fs.read), subsequence read with positionnull
reads the incorrect data.I would expect a read from position 0 followed by a read from null position to read from the next set of data per the documentation:
Save the following to a file and run it.
The text was updated successfully, but these errors were encountered: