I need to read huge chunks of data from a stream. The length of the data is not known before sending. There is no special “end-character” in the stream.
Problem: i get multiple data-events for the stream, and i do not know, when to start the processing of the data.
I know a pattern from other programming languages where i can find out, if there is data left in the TCP stream (e.g. iOS and objective-C, where i have something like “hasBytesAvailable” for NSInputStream-objects).
Does something similar exist in node.js? Or how do i solve the problem with node.js?
Without knowing the length of the data in advance, without an EOF character, and with a held-open socket, you’ll have to make use of the data’s structural properties, i.e. parse it on the fly. That of course presumes the data has known structural properties (e.g. defined video format); if not, either your problem is simply unsolvable or you’ve got an “XY problem” (you’ve prematurely defined a solution without completely defining the real problem).