mafintosh / length-prefixed-stream

Streaming length prefixed buffers
MIT License
45 stars 10 forks source link

cork/uncork in the encoder #2

Open jfromaniello opened 8 years ago

jfromaniello commented 8 years ago

in my code I have something like this:

something.pipe(lps.encode()).pipe(socket);

I think it will make sense to cork/uncork the target stream for the two pushes or push a concat'ed buffer:

  this.push(pool.slice(used - varint.encode.bytes, used))
  this.push(data)

Similar issue in another similar library:

https://github.com/rkusa/frame-stream/issues/4

mafintosh commented 8 years ago

whats the benefit of corking the stream?

jfromaniello commented 8 years ago

as it is today, it generate two writes to the network.

Node seems to call writev each time data is pushed to the piped destination

by corking the socket it just generate one