In recent versions of NodeJS (v0.10.X since writing), the Streams API has gone through a nice redesign, and I would like to start using it now.
I want to wrap both input and output of a socket with an object that implements the protocol.
The so-called Duplex interface seems to be just any stream that can be read and written (like a socket).
It is unclear whether the duplex should look like A or B, or it does not matter.
+---+ +---+ -->| A |--> | |--> +---+ | B | | |<-- +---+
What is the correct code / interface structure for an object that has two records and two reads?
+--------+ +----------+ +---- | r|-->|wr|-->|w | socket | | protocol | | rest of app | w|<--|rw|<--|r +--------+ +----------+ +----
The problem with the above diagram is that the protocol object requires two separate read methods and two write methods.
At the top of my head, I can make the protocol produce βleftβ and βrightβ duplex objects, or βinβ and βexitβ from duplex objects (to crop them differently).
Are they one of the preferred methods or is there a better solution?
source share