|
1 | | -'use strict'; |
| 1 | +'use strict' |
2 | 2 |
|
3 | 3 |
|
4 | | -var Transform = require('stream').Transform; |
5 | | -var streamParser = require('stream-parser'); |
| 4 | +var Transform = require('stream').Transform |
| 5 | +var streamParser = require('stream-parser') |
6 | 6 |
|
7 | 7 |
|
8 | 8 | function ParserStream () { |
9 | | - Transform.call(this, { readableObjectMode: true }); |
| 9 | + Transform.call(this, { readableObjectMode: true }) |
10 | 10 | } |
11 | 11 |
|
12 | 12 | // Inherit from Transform |
13 | | -ParserStream.prototype = Object.create(Transform.prototype); |
14 | | -ParserStream.prototype.constructor = ParserStream; |
| 13 | +ParserStream.prototype = Object.create(Transform.prototype) |
| 14 | +ParserStream.prototype.constructor = ParserStream |
15 | 15 |
|
16 | | -streamParser(ParserStream.prototype); |
| 16 | +streamParser(ParserStream.prototype) |
17 | 17 |
|
18 | 18 |
|
19 | | -exports.ParserStream = ParserStream; |
| 19 | +exports.ParserStream = ParserStream |
20 | 20 |
|
21 | 21 |
|
22 | 22 | exports.sliceEq = function (src, start, dest) { |
23 | 23 | for (var i = start, j = 0; j < dest.length;) { |
24 | | - if (src[i++] !== dest[j++]) return false; |
| 24 | + if (src[i++] !== dest[j++]) return false |
25 | 25 | } |
26 | | - return true; |
27 | | -}; |
| 26 | + return true |
| 27 | +} |
28 | 28 |
|
29 | 29 | exports.str2arr = function (str, format) { |
30 | | - var arr = []; |
31 | | - var i = 0; |
| 30 | + var arr = [] |
| 31 | + var i = 0 |
32 | 32 |
|
33 | 33 | if (format && format === 'hex') { |
34 | 34 | while (i < str.length) { |
35 | | - arr.push(parseInt(str.slice(i, i + 2), 16)); |
36 | | - i += 2; |
| 35 | + arr.push(parseInt(str.slice(i, i + 2), 16)) |
| 36 | + i += 2 |
37 | 37 | } |
38 | 38 | } else { |
39 | 39 | for (; i < str.length; i++) { |
40 | | - arr.push(str.charCodeAt(i) & 0xFF); |
| 40 | + arr.push(str.charCodeAt(i) & 0xFF) |
41 | 41 | } |
42 | 42 | } |
43 | 43 |
|
44 | | - return arr; |
45 | | -}; |
| 44 | + return arr |
| 45 | +} |
46 | 46 |
|
47 | 47 | exports.readUInt16LE = function (data, offset) { |
48 | | - return data[offset] | (data[offset + 1] << 8); |
49 | | -}; |
| 48 | + return data[offset] | (data[offset + 1] << 8) |
| 49 | +} |
50 | 50 |
|
51 | 51 | exports.readUInt16BE = function (data, offset) { |
52 | | - return (data[offset] << 8) | data[offset + 1]; |
53 | | -}; |
| 52 | + return (data[offset] << 8) | data[offset + 1] |
| 53 | +} |
54 | 54 |
|
55 | 55 | exports.readInt16LE = function (data, offset) { |
56 | | - return (exports.readUInt16LE(data, offset) << 16) >> 16; |
57 | | -}; |
| 56 | + return (exports.readUInt16LE(data, offset) << 16) >> 16 |
| 57 | +} |
58 | 58 |
|
59 | 59 | exports.readInt16BE = function (data, offset) { |
60 | | - return (exports.readUInt16BE(data, offset) << 16) >> 16; |
61 | | -}; |
| 60 | + return (exports.readUInt16BE(data, offset) << 16) >> 16 |
| 61 | +} |
62 | 62 |
|
63 | 63 | exports.readUInt32LE = function (data, offset) { |
64 | 64 | return (data[offset] | |
65 | 65 | (data[offset + 1] << 8) | |
66 | 66 | (data[offset + 2] << 16)) + |
67 | | - data[offset + 3] * 0x1000000; |
68 | | -}; |
| 67 | + data[offset + 3] * 0x1000000 |
| 68 | +} |
69 | 69 |
|
70 | 70 | exports.readUInt32BE = function (data, offset) { |
71 | 71 | return data[offset] * 0x1000000 + |
72 | 72 | ((data[offset + 1] << 16) | |
73 | 73 | (data[offset + 2] << 8) | |
74 | | - data[offset + 3]); |
75 | | -}; |
| 74 | + data[offset + 3]) |
| 75 | +} |
76 | 76 |
|
77 | 77 | exports.readInt32LE = function (data, offset) { |
78 | | - return exports.readUInt32LE(data, offset) | 0; |
79 | | -}; |
| 78 | + return exports.readUInt32LE(data, offset) | 0 |
| 79 | +} |
80 | 80 |
|
81 | 81 | exports.readInt32BE = function (data, offset) { |
82 | | - return exports.readUInt32BE(data, offset) | 0; |
83 | | -}; |
| 82 | + return exports.readUInt32BE(data, offset) | 0 |
| 83 | +} |
84 | 84 |
|
85 | 85 |
|
86 | 86 | function ProbeError (message, code, statusCode) { |
87 | | - Error.call(this); |
| 87 | + Error.call(this) |
88 | 88 |
|
89 | 89 | // Include stack trace in error object |
90 | 90 | if (Error.captureStackTrace) { |
91 | 91 | // Chrome and NodeJS |
92 | | - Error.captureStackTrace(this, this.constructor); |
| 92 | + Error.captureStackTrace(this, this.constructor) |
93 | 93 | } else { |
94 | 94 | // FF, IE 10+ and Safari 6+. Fallback for others |
95 | | - this.stack = (new Error()).stack || ''; |
| 95 | + this.stack = (new Error()).stack || '' |
96 | 96 | } |
97 | 97 |
|
98 | | - this.name = this.constructor.name; |
| 98 | + this.name = this.constructor.name |
99 | 99 |
|
100 | | - this.message = message; |
101 | | - if (code) this.code = code; |
102 | | - if (statusCode) this.statusCode = statusCode; |
| 100 | + this.message = message |
| 101 | + if (code) this.code = code |
| 102 | + if (statusCode) this.statusCode = statusCode |
103 | 103 | } |
104 | 104 |
|
105 | 105 | // Inherit from Error |
106 | | -ProbeError.prototype = Object.create(Error.prototype); |
107 | | -ProbeError.prototype.constructor = ProbeError; |
| 106 | +ProbeError.prototype = Object.create(Error.prototype) |
| 107 | +ProbeError.prototype.constructor = ProbeError |
108 | 108 |
|
109 | 109 |
|
110 | | -exports.ProbeError = ProbeError; |
| 110 | +exports.ProbeError = ProbeError |
0 commit comments