1

I have one readable byte-stream and need to distribute it's contents into chunks into writable output streams.

The output streams represent sinks that have a maximum length. So the stream would be read byte by byte and streamed into the writeable stream 1 until it is full. I would then switch to stream 2 write the next bytes and so on.

┌────────────────────────────────────┐                           ┌────────────────────────────────────┐
│                                    │   ┌─────────────────────┐ │┌──────────┐┌──────────┐┌─────────┐ │
│          someInputStream           │──▶│  streamMultiplexer  │ ││ stream1  ││ stream2  ││ stream3 │ │
│                                    │   └─────────────────────┘ │└──────────┘└──────────┘└─────────┘ │
└────────────────────────────────────┘              │            └──────▲───────────▲──────────▲──────┘
                                                    │                   │           │          │       
                                                    └───────────────────┴───────────┴──────────┘       

I could probably do that manually, but I was hoping to find a hint some module that already provides that kind of service. Similarly to what the unix command "split" would do. Only with nodejs streams and pipes..

var someInputStream = ...;

var  = new StreamMultiplexer({
   chunkSize: 1000000,
   writeStreams: [
     stream1, stream2, stream3
   ] 
}) 

someInputStream.pipe(streamMultiplexer);
ash
  • 11
  • 1

0 Answers0