ChunkerTransformStream, a transform stream to take arbitrary chunk sizes and make them consistent
First of all, your code looks great. It brought me to study the internal workings of Node's stream API.

The piece that you're concerned with, and rightfully so, is:

buffer = Buffer.concat([buffer, chunk]);


That's the way to do it. There are no other ways to do what you want to do without using bufferjs, which likely handles things the same way, or less efficiently.

Now, there is one optimization you can make here. By adding the totalLength parameter of Buffer.concat Buffer.concat(list, [totalLength]) you can improve efficiency by avoiding an additional loop in the function, which would need to check the new length of the new buffer.


    Name         Description                                       Required?    Type
    list         List of Buffer objects to concat                  Required     array
    totalLength  Total length of the buffers when concatenated.    Optional     number



  If totalLength is not provided, it is read from the buffers in the
  list. However, this adds an additional loop to the function, so it is
  faster to provide the length explicitly. - See more at:
  http://www.w3resource.com/node.js/nodejs-buffer.php#sthash.qISHPlCO.dpuf


Not sure if this will help or not, but other than that, I don't see any possible optimizations.