-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
stream: add bytesRead property for readable #4372
Conversation
I'm cool w/ the change, but there a test that can be added? Also should probably be accompanied by a docs addition. |
Thanks, @trevnorris , I'd like to add test and docs. |
05727c1
to
d559dd7
Compare
Add test cases and docs. |
|
||
var Readable = require('stream').Readable; | ||
var Duplex = require('stream').Duplex; | ||
var Transform = require('stream').Transform; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preempting the request from others to make these const
EDIT: and anywhere else that the variable doesn't change.
Few comments but LGTM otherwise. |
Add a bytesRead property for readable is useful in some use cases. When user want know how many bytes read of readable, need to caculate it in userland. If encoding is specificed, get the value is very slowly.
d559dd7
to
9a2a446
Compare
Thanks @trevnorris , I updated by your suggestion. |
LGTM |
1 similar comment
LGTM |
Really looking forward to this 👍 |
LGTM. Getting a fresh CI run: https://ci.nodejs.org/job/node-test-pull-request/1234/ |
Failures in CI look unrelated |
Add a bytesRead property for readable is useful in some use cases. When user want know how many bytes read of readable, need to caculate it in userland. If encoding is specificed, get the value is very slowly. PR-URL: #4372 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in bfb2cd0 |
@@ -135,6 +137,7 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { | |||
var e = new Error('stream.unshift() after end event'); | |||
stream.emit('error', e); | |||
} else { | |||
stream.bytesRead += state.objectMode ? 0 : chunk.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you really sure this tracks bytes and not characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an edge case, when encoding of this.push(string)
is same as encoding readable, the string was just pass though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a bit of a problem then? :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to revert this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR coming
This reverts commit bfb2cd0. Refs: nodejs#4372
This reverts commit bfb2cd0. The bytesRead property, as implemented, tracks characters instead of bytes when using an identity encoding. Refs: #4372 PR-URL: #4746 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Add a bytesRead property for readable is useful in some use cases. When user want know how many bytes read of readable, need to caculate it in userland. If encoding is specificed, get the value is very slowly. PR-URL: nodejs#4372 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
This reverts commit bfb2cd0. The bytesRead property, as implemented, tracks characters instead of bytes when using an identity encoding. Refs: nodejs#4372 PR-URL: nodejs#4746 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Add a bytesRead property for readable is
useful in some use cases.
When user want know how many bytes read of
readable, need to caculate it in userland.
If encoding is specificed, get the value is
very slowly.