-
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
docs: fs.write()
variables are not clear
#7868
Comments
I think it's actually the other way round, |
The docs for
Perhaps it would be better if (for both methods) |
Hi! Looking to pick up this issue. Seems relatively easy enough! From my understanding, there is just an ambiguity with It'd make sense to change the word choice to (Also changing Let me know if there is any misunderstanding on my part! |
Thanks for taking it up @jessicaquynh! |
I'm confused here, you start off stating that you think It seems to me that some of the documentation is indeed not clear, but it doesn't seem to me that changing length to size makes any difference. You may think they imply some kind of subtle difference, but I don't have that impression. And if you believe the difference between size and length is so clear, perhaps you can describe the difference clearly? In the absence of a clear and convincing description of why size and length mean different things, I think doc improvements should be focussed on the text which describes the argument's behaviour, not renaming the arguments. |
@sam-github Continuing from your message from the PR. About the commit message: That's my bad. I was thinking back to Java, where I'd be happy to just clarify in the documentation, as opposed to switching out the word choice. |
I didn't know that about java. Yes, I think there is much you can improve in making the text clear, but all the changes in fs don't help, and worse, will make future changes to fs un-backportable to LTS branches. I don't think the length->size change is worth it, but I like your other changes. Sorry, it was probably a lot of work going through fs like that! :-( |
That is, if I recall correctly from my classes at uni. It may have been specific only to DLL and SLL. And it's not a problem at all, it wasn't any work :) I will attempt to make the documentation clearer, rather than changing the syntax! |
Yes, it's just the docs that need clarifying. Length in JS land is almost always an offset into an array or buffer. See array.slice(index, length) for the canonical example.
The idea is to show that fs.write uses size as in a quantity of bytes, not as in an offset.
|
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. Ref: nodejs#7868
Its https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice I find no reference to length in the docs other than as a number of sequential elements: https://developer.mozilla.org/en-US/search?q=length Here's a funny example, https://lodash.com/docs/4.17.2#chunk, you can see the argument is |
@sam-github It's been awhile since this issue has been looked at. The PR has removed the This is a screenshot from Javascript: The Definitive Guide which uses I don't know if there's a good argument, unless @jorangreef has something to add. I certainly agree from a language point of view |
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: #9792 Ref: #7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: nodejs#9792 Ref: nodejs#7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: nodejs#9792 Ref: nodejs#7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: nodejs#9792 Ref: nodejs#7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: nodejs#9792 Ref: nodejs#7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: #9792 Ref: #7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: #9792 Ref: #7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: #9792 Ref: #7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit clarifies variables in the Filesystem docs. Prior, the documentation for fs.write() had an ambiguous remark on the parameters of offset and length. Therefore, this commit makes explicit that the length parameter in fs.write() is used to denote the number of bytes, which is a clearer reference for its usage. PR-URL: #9792 Ref: #7868 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
At least some of this appears to have been addressed. Not sure if there's consensus on the parts that haven't been addressed. This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that. |
The docs for
fs.write()
state:offset
is clear, but one must assume thatlength
has the same meaning as perbuffer.slice(offset, length)
, i.e. thatlength
is not relative tooffset
, but rather an absolute index into buffer as is expected (e.g.string.slice(offset, length)
). Therefore, if one wanted to write 5 bytes from offset 12 at position 1 in the file, one would useoffset=12
,length=12+5
.This is not clear.
I would probably guess that
written
is a quantity number, i.e. if the first call tofs.write()
returnedwritten=2
, then I would think that a count of 2 bytes had been written. I would therefore expect thatfs.write(fd, buffer, offset=12, length=17, position=1)
would returnwritten=5
if everything was written out, and less than5
if a partial write occurred.What actually happens is that
written=17
when the write is fully written out. This is very surprising. Furthermore, ifwritten
now represents an absolute index, is it an absolute index into the source buffer or an absolute index into the target file? If it is an absolute index into the target file, is it relative toposition
or not? It seems thatwritten
is actually then an absolute index relative to the sourcebuffer
?Why is
buffer
returned in the write callback? Is this the same buffer I passed, or a slice? The docs should also make that clear.The text was updated successfully, but these errors were encountered: