Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created July 27, 2012 17:49
Show Gist options
  • Save piscisaureus/3189343 to your computer and use it in GitHub Desktop.
Save piscisaureus/3189343 to your computer and use it in GitHub Desktop.
var buf = null;
var offset = 0;
stream.on('data', function(buf_) {
assert(!buf);
buf = buf_;
stream.emit('readable');
stream.pause();
});
stream.read = function(n) {
if (!buf)
return null;
var left = buf.length - offset;
if (left > n) {
rv = buf.slice(offset, offset + n);
offset += n;
} else {
rv = buf.slice(offset, offset + left);
buf = null;
offset = 0;
stream.resume();
}
return buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment