Cut buffer to package
A cutter for head-body buffer.
Many network protocol will use packets 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. So this
cutter will help to get packets.
var Cutter = require'cutter';var net = require'net';/*** must return length of head + body*/return 4 + data0 + data1 << 8 + data2 << 16;var server = netcreateServervar cutter = 4 packetLength;cutteron'packet'var head = packetslice0 4;var body = packetslice4 packetlength;;socketon'data'cutteremit'data' data;;;serverlisten12345;
npm install cutter