This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Surprising behavior in stream.read(n)
when stream ends
#7273
Labels
Comments
cc @tjfontaine |
@sorccu - Out of interest, what would you expect to see logged to the console?
|
Same as now, I suppose. It's just that the docs fail to mention anything about this case and you're left to figure it out on your own. If you blindly rely on the current docs you're likely to have a bug in your code. |
Yeah, this basically seems like a documentation issue. I wouldn't expect the data to simply be lost. |
@sorccu ... interested in helping out with a PR? :-) |
Can I take this one? |
Sure! On Sunday, June 28, 2015, Philippe Laferriere [email protected]
|
plafer
added a commit
to plafer/node-v0.x-archive
that referenced
this issue
Jun 28, 2015
Made explicitely clear that when size bytes are not available, it will return null, unless we've ended, in which case the data remaining in the buffer will be returned. Fixes nodejs#7273
jasnell
pushed a commit
to jasnell/node-joyent
that referenced
this issue
Jun 29, 2015
Made explicitely clear that when size bytes are not available, it will return null, unless we've ended, in which case the data remaining in the buffer will be returned. Fixes nodejs#7273
jasnell
pushed a commit
to jasnell/node-joyent
that referenced
this issue
Jul 9, 2015
Made explicitely clear that when size bytes are not available, it will return null, unless we've ended, in which case the data remaining in the buffer will be returned. Fixes nodejs#7273 Reviewed-By: James M Snell <[email protected]> PR-URL: nodejs#25592
jasnell
pushed a commit
that referenced
this issue
Aug 4, 2015
Made explicitely clear that when size bytes are not available, it will return null, unless we've ended, in which case the data remaining in the buffer will be returned. Fixes #7273 Reviewed-By: James M Snell <[email protected]> PR-URL: #25591
jBarz
pushed a commit
to ibmruntimes/node
that referenced
this issue
Nov 4, 2016
Made explicitely clear that when size bytes are not available, it will return null, unless we've ended, in which case the data remaining in the buffer will be returned. Fixes nodejs#7273 Reviewed-By: James M Snell <[email protected]> PR-URL: nodejs#25591
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It seems that when a stream ends, and it still has unread data in its buffers, a final
readable
event gets emitted, andstream.read(n)
wheren > unread.length
happily returns the remaining bytes even though it normally wouldn't.Example of said behavior:
(note that the file is considerably smaller than requested 10000 bytes)
Produces:
(i.e. just before ending, it returned what it had, instead of the requested amount)
This behavior is surprising because the documentation lets you believe that
stream.read(n)
can only ever return the requested amount of bytes:I was able to dig a removed explanation for this behavior, and I'm not necessarily questioning the validity of it, but it seems very odd and confusing that none of this is documented and even the useful comment has been removed.
The text was updated successfully, but these errors were encountered: