bug with _read method invocation, or problem with me?

36 views
Skip to first unread message

Dave Clements

unread,
Nov 3, 2013, 5:46:25 PM11/3/13
to nod...@googlegroups.com
I'm guessing probably me, but truly I know not why. 

Take this mock scenario:

var stream = require('stream');
var readable = new stream.Readable();
readable._read = function (size) {
    console.log(size);
}
readable.read(512);


This (with Node 0.10.21) will log 16384 (the high water mark), instead of the expected 512.

Is this a bug or am I doin it wrong?

If someone in the know can confirm as bug I'll be happen to open an issue

Best,
Dave




mscdex

unread,
Nov 3, 2013, 6:24:38 PM11/3/13
to nod...@googlegroups.com
On Sunday, November 3, 2013 5:46:25 PM UTC-5, Dave Clements wrote:
This (with Node 0.10.21) will log 16384 (the high water mark), instead of the expected 512.

David Clements

unread,
Nov 4, 2013, 6:39:27 AM11/4/13
to nod...@googlegroups.com
Hey thanks mscdex, yeah I see that, so I must be misunderstanding how it works, I would have though that the number passed to read would 
carry through to _read, but instead the read method uses it's n parameter independently and always passes in the high water mark?


--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/bCtkcP2aOig/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
David Mark Clements Ltd is a company registered in Northern Ireland. Registered number: NI617728. Registered office: Unit 22a, Pennybridge Industrial Estate, 
Ballymena, Antrim, BT42 3HB

mscdex

unread,
Nov 4, 2013, 7:25:38 AM11/4/13
to nod...@googlegroups.com, hupere...@googlemail.com
On Monday, November 4, 2013 6:39:27 AM UTC-5, David Clements wrote:
Hey thanks mscdex, yeah I see that, so I must be misunderstanding how it works, I would have though that the number passed to read would 
carry through to _read, but instead the read method uses it's n parameter independently and always passes in the high water mark?


My guess is efficiency/performance (reading one large Buffer vs reading x individual smaller Buffers possibly needing concatenation to reach n). Another thing to remember is that `read(n)` will return *at least* n bytes.
Reply all
Reply to author
Forward
0 new messages