Reading until terminator makes for a bad day #30

bmeck opened this Issue Oct 29, 2012 · 7 comments


None yet
7 participants

bmeck commented Oct 29, 2012

Doing something equivalent to reading a null terminated string is horrifyingly hard to do right now if you want to read after it. Otherwise replays must be used or intermediate streams for buffering etc.

Imagine a structure with a null terminated string followed by a single byte:

Currently (holy crap allocations / problems):

var str = new Buffer();
// Must read one at a time so that read(x) works after the null
// without doing screwy replays
while (c = && c[0] !== 0x00) {
  str = Buffer.concat(str, c);
// inclusive i guess?
str = Buffer.concat(str, new Buffer([0]);
// Now read(x) still works right without replays!

A nice to have would be:


+1 for readUntil().


TooTallNate commented Nov 19, 2012

I think a low-level .peek(n) function would be more beneficial. It would act just like the .read(n) function, except it wouldn't remove the Buffer from the stream. This would be the low-level building block that you could implement .readUntil(x) in in a performant way.


Raynos commented Nov 19, 2012

+1 for .peek()


bmeck commented Nov 19, 2012

@TooTallNate peek seems fine to me +1

dscape commented Dec 18, 2012


this reminds me more and more of


rvagg commented Jan 9, 2014

closing under the assumption that this is stale. If there's still something to discuss then joyent/node would be the place to discuss it now.

@rvagg rvagg closed this Jan 9, 2014

@bmeck bmeck referenced this issue in whatwg/streams Feb 9, 2014


Pull based streams: ability to read $num items #74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment