Overview
When transfer packets in network composed of a fixed length "head" and a variable length "body", the "data" event emitted by node socket probably not a complete packet, but part of several packets. This tool help you get the "head" and "body" from the buffers.
If the "head" and "body" is in a single buffer, data will not be copyed to a new buffer, just use buffer.slice() to reference data.
see the test for more usage samples.
Install
npm install head_body_buffers
Example
var net = ;var HeadBodyBuffers = HeadBodyBuffers; { var len = data0; len += data1 << 8; len += data2 << 16; return len;} var hbd = 4 packetLength;hbd; var client = net;client;