Repository navigation
streams: Readable highWaterMark is measured in bytes *or* characters #6798
Description
Activity
- addedstreamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
on May 17, 2016 My initial take on this is that measuring characters is a bug.
Reacted by amauri and Matteo Collina@jasnell I agree! this is a nice issue if anybody wants to start contributing on streams and on core cc @nodejs/streams.
- addedgood first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
on May 17, 2016 I'd be interested in digging into this to learn more about streams.... will take a look in the morning
One other issue to think about with this is when someone calls
setEncoding()whenstate.length > 0, what to do then? Convert all the buffered data to strings and updatestate.lengthor just loop through the buffer usingBuffer.byteLength(chunk, encoding)to updatestate.length?I think we should just use byte length for highWaterMark. Converting values... sounds tricky.
Hi! It seems like it's been awhile since anyone's mentioned anything on this issue. Does anyone mind if I take a go at this?
@jessicaquynh please do! Ping @nodejs/streams if you need any help.
@mcollina Thanks! Should I also include a test for this change?
@jessicaquynh yes please!
Great, will do! Thanks @cjihrig!
@nodejs/streams would love some guidance! The implementation that I made has caused a side-effect and I am unsure what to do to fix it.
I have changed this line to write the
chunk.length(if not in objectMode) to be a convertedBuffer.byteLength(chunk, encoding).However, the most recent version of
_stream_readable.jshas this line that conflicts with the change.This
ifstatement gets entered pre-emptively when the byteLength is quite low. Say, 2 or 4 and it throws the error thatstate.buffer.headis undefined. The difference is in these instances, the string chunk length was 0. I notice that the file on master and the file in this issue's reference contain a differenthowMuchToReadfunction. So perhaps the new function got rewritten without this bug in mind?Anyhow, any help or feedback would be greatly appreciated! Thanks! :)
21 remaining items
- added a commit that references this issue
on Sep 8, 2017 - added a commit that references this issue
on Sep 13, 2017 Yes, I think this could be closed.
Reacted by Gireesh Punathil
Currently the Readable streams documentation states that
highWaterMarkis measured in bytes for non-object mode streams. However, when.setEncoding()is called on the Readable stream, thenhighWaterMarkis measured in characters and not bytes sincestate.length += chunk.lengthhappens afterchunkis overwritten with a decoded string andstate.lengthis what is compared withhighWaterMark.This seems to be an issue since at least v0.10, so I wasn't sure if we should just update the documentation to note this behavior or if we should change the existing behavior to match the documentation.
/cc @nodejs/streams