I've been messing around with 0.10's Stream.Readable this morning trying to
get a super simple example to work, but I can't get my subclass to emit any
"readable" events. Here's the subclass I'm using:
function Content(string, options) {
Stream.Readable.call(this, options);
this.push(string);
}
util.inherits(Content, Stream.Readable);
Content.prototype._read = function (size) {
// Ignore size argument and return the entire buffer, for now.
var state = this._readableState;
var chunk = Buffer.concat(state.buffer);
state.buffer = [];
return chunk;
};
All I'm trying to do is wrap a string with a Stream.Readable subclass and
emit that string. My _read function ignores the size argument for the sake
of simplicity.
Here's my test case:
var test = new Content('hello world');
// console.log(test._readableState.buffer.map(function (o) { return
o.toString() }))
test.on('readable', function () {
console.log('readable');
console.log(test.read());
});
test.on('error', function (error) {
console.log(error);
});
test.on('end', function () {
console.log('end');
});
When I run this code, I don't get anything printed to the console. Not even
if I try a test.read(0) afterwards to refresh the internal buffer.
I know there's stuff in the internal buffer because when I run the line
that's commented out it shows me that my string is there.
What am I doing wrong? Thanks in advance.
--
Michael Jackson
@mjackson
--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.