Googling for "parse nodejs binary stream" I see lots of examples when the emitted data fits neatly into the expected return size, but zero examples of how to handle the case when the next chunk contains the remaining bytes from the first structure and the new header.
What's the "right" way to parse binary streams when I expect something like:
record-length: 4bytes
data1: 8bytes
data2: 8bytes
4-byte-records[(record-length - 16) * 4];
The data will come in as various sized chunks. But is there a way to call data.readUInt32(0) and have it wait for the chunk to fill? I'd hate to have to write a pipe stage that emits bytes and a receiving state machine, that seems so very wrong.
This has got to be solved, it is such a basic concept.
Help?
Thanks, PT