How to fill buffer till end?

23 views
Skip to first unread message

i...@bodokaiser.io

unread,
Feb 14, 2014, 4:22:11 PM2/14/14
to nod...@googlegroups.com
Hey,

I have a transform stream (something like the Incoming in https://github.com/isaacs/simple-protocol).

I now would like to keep the underlaying TCP socket alive for new Incoming streams.

I think wrapping the tcp socket into a Duplex stream which creates a new Incoming transform instance each time when the previous Incoming is full.

This sounds easy however I fail finding a solution to know when the transform stream has consumed enough data. Listening on the "end" event is not a reliable option as the last chunk could already contain data for the next Incoming message.

Anyone am idea?

Best,
Bo

Bodo Kaiser

unread,
Feb 15, 2014, 4:54:52 AM2/15/14
to nod...@googlegroups.com
So for those who are interested:

I found out that the most easiest way is to emit remaining chunk at the end of the stream before doing `this.push(null)`.

Then we only must create on the emitted chunk a new stream instance and write it onto it.
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/Wgpkk_BGwWo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages