Closed jamestalmage closed 8 years ago
👍 I assume you want an error thrown when it reaches the maximum. For the array method, maybe it should count array items instead of bytes?
My thought was that if you set maxBuffer, every item passed in must have a numeric length
property.
Maybe a maxItems
option, only for arrays? That way you can still use maxBuffer for arrays if there is a length property
Ok, so how about this; We do the same for all the methods and limit on the total byte size, but if it's an object stream (accepted in .array()
), we do the same as the stream highWaterMark
option and work on items, not on byte size. ?
When in objectMode, streams can push Strings and Buffers as well as any other JavaScript object. Another major difference is that when in objectMode, the internal buffering algorithm counts objects rather than bytes. This means if we have a Transform stream with the highWaterMark option set to 5, the stream will only buffer a maximum of 5 objects internally. - https://nodesource.com/blog/understanding-object-streams/
Sidenote: Object streams feels very similar to Observables, although with back-pressure support and no utility methods.
Re: Observables
Yep, that's it essentially.
A stream of strings is still in objectMode though (I believe). So you couldn't do:
getStream(stream.pipe (split()))
Are you sure? I don't see any objectMode
reference here: https://github.com/dominictarr/split/blob/master/index.js
No. Definitely not sure.
From the article:
If an object stream isn't emitting Strings or Buffers, it's important to note that you can't pipe it to a non-object stream.
So it looks like maybe objectMode
is taken into account on the stream you are piping to?
So if I'm setting up a transform stream that takes in Strings/Buffers and emits Objects, is that not an ObjectMode stream (because it doesn't take objects)? I think that's what I'm reading.
So if I'm setting up a transform stream that takes in Strings/Buffers and emits Objects, is that not an ObjectMode stream (because it doesn't take objects)? I think that's what I'm reading.
Yup, I think only the receiving one needs to be.
https://github.com/jamestalmage2/stream-objectmode-tests
That turned out to have a few surprises.
@jamestalmage That's useful info! You should submit a link to the repo to https://github.com/stephenplusplus/stream-faqs ;)
See https://github.com/sindresorhus/execa/issues/33