UNPKG

549 BJavaScriptView Raw
1module.exports = compact2string = function (buf) {
2
3 if(buf.length !== 6)
4 throw new Error("Invalid Compact IP/PORT, It should contain 6 bytes");
5
6 return buf[0] + "." + buf[1] + "." + buf[2] + "." + buf[3] + ":" + buf.readUInt16BE(4);
7};
8
9compact2string.multi = function (buf) {
10
11 if(buf.length % 6 !== 0)
12 throw new Error("buf length isn't multiple of compact IP/PORTs (6 bytes)");
13
14 var output = [];
15 for (var i = 0; i <= buf.length - 1; i = i + 6) {
16 output.push(compact2string(buf.slice(i, i + 6)));
17 }
18
19 return output;
20
21};
22