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?
The methods you refer to don't do what you say they do. They only tell you how much data can be read without blocking. Not the same thing at all.
The only way to read to the end of a stream is to read to the end of the stream. You will get an EOS when it is finished.
There isn't actually such a thing as the 'length of the data' when it comes from a network stream: consider that the peer could keep writing data forever.
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).