@@ -26,7 +26,7 @@ float32Array[0] = -1; // 0xBF800000 |
26 | 26 | const bigEndian = uInt8Float32Array[3] === 0; |
27 | 27 |
|
28 | 28 | function checkBounds(buf, offset, byteLength) { |
29 | | - checkNumberType(offset); |
| 29 | + validateNumber(offset, 'offset'); |
30 | 30 | if (buf[offset] === undefined || buf[offset + byteLength] === undefined) |
31 | 31 | boundsError(offset, buf.length - (byteLength + 1)); |
32 | 32 | } |
@@ -38,13 +38,9 @@ function checkInt(value, min, max, buf, offset, byteLength) { |
38 | 38 | checkBounds(buf, offset, byteLength); |
39 | 39 | } |
40 | 40 |
|
41 | | -function checkNumberType(value, type) { |
42 | | - validateNumber(value, type || 'offset'); |
43 | | -} |
44 | | - |
45 | 41 | function boundsError(value, length, type) { |
46 | 42 | if (Math.floor(value) !== value) { |
47 | | - checkNumberType(value, type); |
| 43 | + validateNumber(value, type); |
48 | 44 | throw new ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value); |
49 | 45 | } |
50 | 46 |
|
@@ -77,7 +73,7 @@ function readUIntLE(offset, byteLength) { |
77 | 73 | } |
78 | 74 |
|
79 | 75 | function readUInt48LE(buf, offset = 0) { |
80 | | - checkNumberType(offset); |
| 76 | + validateNumber(offset, 'offset'); |
81 | 77 | const first = buf[offset]; |
82 | 78 | const last = buf[offset + 5]; |
83 | 79 | if (first === undefined || last === undefined) |
@@ -91,7 +87,7 @@ function readUInt48LE(buf, offset = 0) { |
91 | 87 | } |
92 | 88 |
|
93 | 89 | function readUInt40LE(buf, offset = 0) { |
94 | | - checkNumberType(offset); |
| 90 | + validateNumber(offset, 'offset'); |
95 | 91 | const first = buf[offset]; |
96 | 92 | const last = buf[offset + 4]; |
97 | 93 | if (first === undefined || last === undefined) |
@@ -105,7 +101,7 @@ function readUInt40LE(buf, offset = 0) { |
105 | 101 | } |
106 | 102 |
|
107 | 103 | function readUInt32LE(offset = 0) { |
108 | | - checkNumberType(offset); |
| 104 | + validateNumber(offset, 'offset'); |
109 | 105 | const first = this[offset]; |
110 | 106 | const last = this[offset + 3]; |
111 | 107 | if (first === undefined || last === undefined) |
@@ -118,7 +114,7 @@ function readUInt32LE(offset = 0) { |
118 | 114 | } |
119 | 115 |
|
120 | 116 | function readUInt24LE(buf, offset = 0) { |
121 | | - checkNumberType(offset); |
| 117 | + validateNumber(offset, 'offset'); |
122 | 118 | const first = buf[offset]; |
123 | 119 | const last = buf[offset + 2]; |
124 | 120 | if (first === undefined || last === undefined) |
@@ -128,7 +124,7 @@ function readUInt24LE(buf, offset = 0) { |
128 | 124 | } |
129 | 125 |
|
130 | 126 | function readUInt16LE(offset = 0) { |
131 | | - checkNumberType(offset); |
| 127 | + validateNumber(offset, 'offset'); |
132 | 128 | const first = this[offset]; |
133 | 129 | const last = this[offset + 1]; |
134 | 130 | if (first === undefined || last === undefined) |
@@ -138,7 +134,7 @@ function readUInt16LE(offset = 0) { |
138 | 134 | } |
139 | 135 |
|
140 | 136 | function readUInt8(offset = 0) { |
141 | | - checkNumberType(offset); |
| 137 | + validateNumber(offset, 'offset'); |
142 | 138 | const val = this[offset]; |
143 | 139 | if (val === undefined) |
144 | 140 | boundsError(offset, this.length - 1); |
@@ -166,7 +162,7 @@ function readUIntBE(offset, byteLength) { |
166 | 162 | } |
167 | 163 |
|
168 | 164 | function readUInt48BE(buf, offset = 0) { |
169 | | - checkNumberType(offset); |
| 165 | + validateNumber(offset, 'offset'); |
170 | 166 | const first = buf[offset]; |
171 | 167 | const last = buf[offset + 5]; |
172 | 168 | if (first === undefined || last === undefined) |
@@ -180,7 +176,7 @@ function readUInt48BE(buf, offset = 0) { |
180 | 176 | } |
181 | 177 |
|
182 | 178 | function readUInt40BE(buf, offset = 0) { |
183 | | - checkNumberType(offset); |
| 179 | + validateNumber(offset, 'offset'); |
184 | 180 | const first = buf[offset]; |
185 | 181 | const last = buf[offset + 4]; |
186 | 182 | if (first === undefined || last === undefined) |
@@ -194,7 +190,7 @@ function readUInt40BE(buf, offset = 0) { |
194 | 190 | } |
195 | 191 |
|
196 | 192 | function readUInt32BE(offset = 0) { |
197 | | - checkNumberType(offset); |
| 193 | + validateNumber(offset, 'offset'); |
198 | 194 | const first = this[offset]; |
199 | 195 | const last = this[offset + 3]; |
200 | 196 | if (first === undefined || last === undefined) |
@@ -207,7 +203,7 @@ function readUInt32BE(offset = 0) { |
207 | 203 | } |
208 | 204 |
|
209 | 205 | function readUInt24BE(buf, offset = 0) { |
210 | | - checkNumberType(offset); |
| 206 | + validateNumber(offset, 'offset'); |
211 | 207 | const first = buf[offset]; |
212 | 208 | const last = buf[offset + 2]; |
213 | 209 | if (first === undefined || last === undefined) |
@@ -217,7 +213,7 @@ function readUInt24BE(buf, offset = 0) { |
217 | 213 | } |
218 | 214 |
|
219 | 215 | function readUInt16BE(offset = 0) { |
220 | | - checkNumberType(offset); |
| 216 | + validateNumber(offset, 'offset'); |
221 | 217 | const first = this[offset]; |
222 | 218 | const last = this[offset + 1]; |
223 | 219 | if (first === undefined || last === undefined) |
@@ -246,7 +242,7 @@ function readIntLE(offset, byteLength) { |
246 | 242 | } |
247 | 243 |
|
248 | 244 | function readInt48LE(buf, offset = 0) { |
249 | | - checkNumberType(offset); |
| 245 | + validateNumber(offset, 'offset'); |
250 | 246 | const first = buf[offset]; |
251 | 247 | const last = buf[offset + 5]; |
252 | 248 | if (first === undefined || last === undefined) |
@@ -261,7 +257,7 @@ function readInt48LE(buf, offset = 0) { |
261 | 257 | } |
262 | 258 |
|
263 | 259 | function readInt40LE(buf, offset = 0) { |
264 | | - checkNumberType(offset); |
| 260 | + validateNumber(offset, 'offset'); |
265 | 261 | const first = buf[offset]; |
266 | 262 | const last = buf[offset + 4]; |
267 | 263 | if (first === undefined || last === undefined) |
@@ -275,7 +271,7 @@ function readInt40LE(buf, offset = 0) { |
275 | 271 | } |
276 | 272 |
|
277 | 273 | function readInt32LE(offset = 0) { |
278 | | - checkNumberType(offset); |
| 274 | + validateNumber(offset, 'offset'); |
279 | 275 | const first = this[offset]; |
280 | 276 | const last = this[offset + 3]; |
281 | 277 | if (first === undefined || last === undefined) |
@@ -288,7 +284,7 @@ function readInt32LE(offset = 0) { |
288 | 284 | } |
289 | 285 |
|
290 | 286 | function readInt24LE(buf, offset = 0) { |
291 | | - checkNumberType(offset); |
| 287 | + validateNumber(offset, 'offset'); |
292 | 288 | const first = buf[offset]; |
293 | 289 | const last = buf[offset + 2]; |
294 | 290 | if (first === undefined || last === undefined) |
@@ -299,7 +295,7 @@ function readInt24LE(buf, offset = 0) { |
299 | 295 | } |
300 | 296 |
|
301 | 297 | function readInt16LE(offset = 0) { |
302 | | - checkNumberType(offset); |
| 298 | + validateNumber(offset, 'offset'); |
303 | 299 | const first = this[offset]; |
304 | 300 | const last = this[offset + 1]; |
305 | 301 | if (first === undefined || last === undefined) |
@@ -310,7 +306,7 @@ function readInt16LE(offset = 0) { |
310 | 306 | } |
311 | 307 |
|
312 | 308 | function readInt8(offset = 0) { |
313 | | - checkNumberType(offset); |
| 309 | + validateNumber(offset, 'offset'); |
314 | 310 | const val = this[offset]; |
315 | 311 | if (val === undefined) |
316 | 312 | boundsError(offset, this.length - 1); |
@@ -338,7 +334,7 @@ function readIntBE(offset, byteLength) { |
338 | 334 | } |
339 | 335 |
|
340 | 336 | function readInt48BE(buf, offset = 0) { |
341 | | - checkNumberType(offset); |
| 337 | + validateNumber(offset, 'offset'); |
342 | 338 | const first = buf[offset]; |
343 | 339 | const last = buf[offset + 5]; |
344 | 340 | if (first === undefined || last === undefined) |
@@ -353,7 +349,7 @@ function readInt48BE(buf, offset = 0) { |
353 | 349 | } |
354 | 350 |
|
355 | 351 | function readInt40BE(buf, offset = 0) { |
356 | | - checkNumberType(offset); |
| 352 | + validateNumber(offset, 'offset'); |
357 | 353 | const first = buf[offset]; |
358 | 354 | const last = buf[offset + 4]; |
359 | 355 | if (first === undefined || last === undefined) |
@@ -367,7 +363,7 @@ function readInt40BE(buf, offset = 0) { |
367 | 363 | } |
368 | 364 |
|
369 | 365 | function readInt32BE(offset = 0) { |
370 | | - checkNumberType(offset); |
| 366 | + validateNumber(offset, 'offset'); |
371 | 367 | const first = this[offset]; |
372 | 368 | const last = this[offset + 3]; |
373 | 369 | if (first === undefined || last === undefined) |
@@ -380,7 +376,7 @@ function readInt32BE(offset = 0) { |
380 | 376 | } |
381 | 377 |
|
382 | 378 | function readInt24BE(buf, offset = 0) { |
383 | | - checkNumberType(offset); |
| 379 | + validateNumber(offset, 'offset'); |
384 | 380 | const first = buf[offset]; |
385 | 381 | const last = buf[offset + 2]; |
386 | 382 | if (first === undefined || last === undefined) |
@@ -391,7 +387,7 @@ function readInt24BE(buf, offset = 0) { |
391 | 387 | } |
392 | 388 |
|
393 | 389 | function readInt16BE(offset = 0) { |
394 | | - checkNumberType(offset); |
| 390 | + validateNumber(offset, 'offset'); |
395 | 391 | const first = this[offset]; |
396 | 392 | const last = this[offset + 1]; |
397 | 393 | if (first === undefined || last === undefined) |
@@ -403,7 +399,7 @@ function readInt16BE(offset = 0) { |
403 | 399 |
|
404 | 400 | // Read floats |
405 | 401 | function readFloatBackwards(offset = 0) { |
406 | | - checkNumberType(offset); |
| 402 | + validateNumber(offset, 'offset'); |
407 | 403 | const first = this[offset]; |
408 | 404 | const last = this[offset + 3]; |
409 | 405 | if (first === undefined || last === undefined) |
@@ -417,7 +413,7 @@ function readFloatBackwards(offset = 0) { |
417 | 413 | } |
418 | 414 |
|
419 | 415 | function readFloatForwards(offset = 0) { |
420 | | - checkNumberType(offset); |
| 416 | + validateNumber(offset, 'offset'); |
421 | 417 | const first = this[offset]; |
422 | 418 | const last = this[offset + 3]; |
423 | 419 | if (first === undefined || last === undefined) |
@@ -431,7 +427,7 @@ function readFloatForwards(offset = 0) { |
431 | 427 | } |
432 | 428 |
|
433 | 429 | function readDoubleBackwards(offset = 0) { |
434 | | - checkNumberType(offset); |
| 430 | + validateNumber(offset, 'offset'); |
435 | 431 | const first = this[offset]; |
436 | 432 | const last = this[offset + 7]; |
437 | 433 | if (first === undefined || last === undefined) |
@@ -449,7 +445,7 @@ function readDoubleBackwards(offset = 0) { |
449 | 445 | } |
450 | 446 |
|
451 | 447 | function readDoubleForwards(offset = 0) { |
452 | | - checkNumberType(offset); |
| 448 | + validateNumber(offset, 'offset'); |
453 | 449 | const first = this[offset]; |
454 | 450 | const last = this[offset + 7]; |
455 | 451 | if (first === undefined || last === undefined) |
@@ -563,7 +559,7 @@ function writeUInt16LE(value, offset = 0) { |
563 | 559 | function writeU_Int8(buf, value, offset, min, max) { |
564 | 560 | value = +value; |
565 | 561 | // `checkInt()` can not be used here because it checks two entries. |
566 | | - checkNumberType(offset); |
| 562 | + validateNumber(offset, 'offset'); |
567 | 563 | if (value > max || value < min) { |
568 | 564 | throw new ERR_OUT_OF_RANGE('value', `>= ${min} and <= ${max}`, value); |
569 | 565 | } |
|