-
-
Save isaacs/5010496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require('assert'); | |
var stream = require('stream'); | |
var r = new stream.Readable({ encoding: 'ascii' }); | |
// at the first read, no data is available yet. | |
var s = [['','',''],['a','b','c'],['d','e','f'],['g','h','i']]; | |
r._read = function(n, cb) { | |
console.error('_READ', s[0] ? s[0].join('') : 'EOF'); | |
var l = s.shift(); | |
if (l) { | |
r.push(l[0]); | |
r.push(l[1]); | |
r.push(l[2]); | |
} else { | |
cb(null, null); | |
} | |
}; | |
var ended = false; | |
r.on('end', function() { | |
ended = true; | |
}); | |
assert.equal(r.read(), null); | |
assert.equal(r.read(), 'abc'); | |
r.push('1'); | |
r.push('2'); | |
r.push('3'); | |
assert.equal(r.read(), '123def'); | |
assert.equal(r.read(), 'ghi'); | |
assert.equal(r.read(), null); | |
process.on('exit', function() { | |
assert(ended); | |
console.log('ok'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment