After looking at how Object Mode affects string decoding in Node.js, it got me thinking about Object Mode at a more philosophical level. How should we, as Node.js developers, think about streams in Object Mode? And, how should the nature of the data reflect the configuration of streams? This is a question of intent, not necessarily of technical mechanics.
If you look at the Node.js Stream documentation, on "Object Mode," it states:
A Readable stream in object mode will always return a single item from a call to stream.read(size), regardless of what the size argument is.... No streams in Node core are object mode streams. This pattern is only used by userland streaming libraries.
This makes sense because Object Mode streams deal with distinct, finite values - not with "chunks" that are aggregated into a single, non-divisible value over time. But, does this relationship between Object Mode and read size constitue a symmetric relationship? Meaning, if I am building a Readable stream and each invocation of .push() deals with a distinct, finite value, should I configure the stream to run in "Object Mode"?
| || || |
| || |
| || || |
To frame it another way, if I wrote a stream that only pushed distinct, finite values, I don't think I could offer up a good counter explanation. Meaning, I don't think I could come up with a compelling reason as to why the Stream was NOT running in Object Mode. Sure, I could lean on, "that's just how streams work;" but, to me, this only speaks to a lack of intent.
As always, I must caveat that my Node.js experience is quite limited. So, I would be very interested in hearing what more seasoned Node.js developers have to say on the matter.
Looking For A New Job?
Ooops, there are no jobs. Post one now for only $29 and own this real estate!