@@ -25,7 +25,7 @@ float32Array[0] = -1; // 0xBF800000 |
25 | 25 | const bigEndian = uInt8Float32Array[3] === 0; |
26 | 26 |
|
27 | 27 | function checkBounds(buf, offset, byteLength) { |
28 | | - checkNumberType(offset); |
| 28 | + validateNumber(offset, 'offset'); |
29 | 29 | if (buf[offset] === undefined || buf[offset + byteLength] === undefined) |
30 | 30 | boundsError(offset, buf.length - (byteLength + 1)); |
31 | 31 | } |
@@ -37,13 +37,9 @@ function checkInt(value, min, max, buf, offset, byteLength) { |
37 | 37 | checkBounds(buf, offset, byteLength); |
38 | 38 | } |
39 | 39 |
|
40 | | -function checkNumberType(value, type) { |
41 | | - validateNumber(value, type || 'offset'); |
42 | | -} |
43 | | - |
44 | 40 | function boundsError(value, length, type) { |
45 | 41 | if (Math.floor(value) !== value) { |
46 | | - checkNumberType(value, type); |
| 42 | + validateNumber(value, type); |
47 | 43 | throw new ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value); |
48 | 44 | } |
49 | 45 |
|
@@ -74,7 +70,7 @@ function readUIntLE(offset, byteLength) { |
74 | 70 | } |
75 | 71 |
|
76 | 72 | function readUInt48LE(buf, offset = 0) { |
77 | | - checkNumberType(offset); |
| 73 | + validateNumber(offset, 'offset'); |
78 | 74 | const first = buf[offset]; |
79 | 75 | const last = buf[offset + 5]; |
80 | 76 | if (first === undefined || last === undefined) |
@@ -88,7 +84,7 @@ function readUInt48LE(buf, offset = 0) { |
88 | 84 | } |
89 | 85 |
|
90 | 86 | function readUInt40LE(buf, offset = 0) { |
91 | | - checkNumberType(offset); |
| 87 | + validateNumber(offset, 'offset'); |
92 | 88 | const first = buf[offset]; |
93 | 89 | const last = buf[offset + 4]; |
94 | 90 | if (first === undefined || last === undefined) |
@@ -102,7 +98,7 @@ function readUInt40LE(buf, offset = 0) { |
102 | 98 | } |
103 | 99 |
|
104 | 100 | function readUInt32LE(offset = 0) { |
105 | | - checkNumberType(offset); |
| 101 | + validateNumber(offset, 'offset'); |
106 | 102 | const first = this[offset]; |
107 | 103 | const last = this[offset + 3]; |
108 | 104 | if (first === undefined || last === undefined) |
@@ -115,7 +111,7 @@ function readUInt32LE(offset = 0) { |
115 | 111 | } |
116 | 112 |
|
117 | 113 | function readUInt24LE(buf, offset = 0) { |
118 | | - checkNumberType(offset); |
| 114 | + validateNumber(offset, 'offset'); |
119 | 115 | const first = buf[offset]; |
120 | 116 | const last = buf[offset + 2]; |
121 | 117 | if (first === undefined || last === undefined) |
@@ -125,7 +121,7 @@ function readUInt24LE(buf, offset = 0) { |
125 | 121 | } |
126 | 122 |
|
127 | 123 | function readUInt16LE(offset = 0) { |
128 | | - checkNumberType(offset); |
| 124 | + validateNumber(offset, 'offset'); |
129 | 125 | const first = this[offset]; |
130 | 126 | const last = this[offset + 1]; |
131 | 127 | if (first === undefined || last === undefined) |
@@ -135,7 +131,7 @@ function readUInt16LE(offset = 0) { |
135 | 131 | } |
136 | 132 |
|
137 | 133 | function readUInt8(offset = 0) { |
138 | | - checkNumberType(offset); |
| 134 | + validateNumber(offset, 'offset'); |
139 | 135 | const val = this[offset]; |
140 | 136 | if (val === undefined) |
141 | 137 | boundsError(offset, this.length - 1); |
@@ -161,7 +157,7 @@ function readUIntBE(offset, byteLength) { |
161 | 157 | } |
162 | 158 |
|
163 | 159 | function readUInt48BE(buf, offset = 0) { |
164 | | - checkNumberType(offset); |
| 160 | + validateNumber(offset, 'offset'); |
165 | 161 | const first = buf[offset]; |
166 | 162 | const last = buf[offset + 5]; |
167 | 163 | if (first === undefined || last === undefined) |
@@ -175,7 +171,7 @@ function readUInt48BE(buf, offset = 0) { |
175 | 171 | } |
176 | 172 |
|
177 | 173 | function readUInt40BE(buf, offset = 0) { |
178 | | - checkNumberType(offset); |
| 174 | + validateNumber(offset, 'offset'); |
179 | 175 | const first = buf[offset]; |
180 | 176 | const last = buf[offset + 4]; |
181 | 177 | if (first === undefined || last === undefined) |
@@ -189,7 +185,7 @@ function readUInt40BE(buf, offset = 0) { |
189 | 185 | } |
190 | 186 |
|
191 | 187 | function readUInt32BE(offset = 0) { |
192 | | - checkNumberType(offset); |
| 188 | + validateNumber(offset, 'offset'); |
193 | 189 | const first = this[offset]; |
194 | 190 | const last = this[offset + 3]; |
195 | 191 | if (first === undefined || last === undefined) |
@@ -202,7 +198,7 @@ function readUInt32BE(offset = 0) { |
202 | 198 | } |
203 | 199 |
|
204 | 200 | function readUInt24BE(buf, offset = 0) { |
205 | | - checkNumberType(offset); |
| 201 | + validateNumber(offset, 'offset'); |
206 | 202 | const first = buf[offset]; |
207 | 203 | const last = buf[offset + 2]; |
208 | 204 | if (first === undefined || last === undefined) |
@@ -212,7 +208,7 @@ function readUInt24BE(buf, offset = 0) { |
212 | 208 | } |
213 | 209 |
|
214 | 210 | function readUInt16BE(offset = 0) { |
215 | | - checkNumberType(offset); |
| 211 | + validateNumber(offset, 'offset'); |
216 | 212 | const first = this[offset]; |
217 | 213 | const last = this[offset + 1]; |
218 | 214 | if (first === undefined || last === undefined) |
@@ -239,7 +235,7 @@ function readIntLE(offset, byteLength) { |
239 | 235 | } |
240 | 236 |
|
241 | 237 | function readInt48LE(buf, offset = 0) { |
242 | | - checkNumberType(offset); |
| 238 | + validateNumber(offset, 'offset'); |
243 | 239 | const first = buf[offset]; |
244 | 240 | const last = buf[offset + 5]; |
245 | 241 | if (first === undefined || last === undefined) |
@@ -254,7 +250,7 @@ function readInt48LE(buf, offset = 0) { |
254 | 250 | } |
255 | 251 |
|
256 | 252 | function readInt40LE(buf, offset = 0) { |
257 | | - checkNumberType(offset); |
| 253 | + validateNumber(offset, 'offset'); |
258 | 254 | const first = buf[offset]; |
259 | 255 | const last = buf[offset + 4]; |
260 | 256 | if (first === undefined || last === undefined) |
@@ -268,7 +264,7 @@ function readInt40LE(buf, offset = 0) { |
268 | 264 | } |
269 | 265 |
|
270 | 266 | function readInt32LE(offset = 0) { |
271 | | - checkNumberType(offset); |
| 267 | + validateNumber(offset, 'offset'); |
272 | 268 | const first = this[offset]; |
273 | 269 | const last = this[offset + 3]; |
274 | 270 | if (first === undefined || last === undefined) |
@@ -281,7 +277,7 @@ function readInt32LE(offset = 0) { |
281 | 277 | } |
282 | 278 |
|
283 | 279 | function readInt24LE(buf, offset = 0) { |
284 | | - checkNumberType(offset); |
| 280 | + validateNumber(offset, 'offset'); |
285 | 281 | const first = buf[offset]; |
286 | 282 | const last = buf[offset + 2]; |
287 | 283 | if (first === undefined || last === undefined) |
@@ -292,7 +288,7 @@ function readInt24LE(buf, offset = 0) { |
292 | 288 | } |
293 | 289 |
|
294 | 290 | function readInt16LE(offset = 0) { |
295 | | - checkNumberType(offset); |
| 291 | + validateNumber(offset, 'offset'); |
296 | 292 | const first = this[offset]; |
297 | 293 | const last = this[offset + 1]; |
298 | 294 | if (first === undefined || last === undefined) |
@@ -303,7 +299,7 @@ function readInt16LE(offset = 0) { |
303 | 299 | } |
304 | 300 |
|
305 | 301 | function readInt8(offset = 0) { |
306 | | - checkNumberType(offset); |
| 302 | + validateNumber(offset, 'offset'); |
307 | 303 | const val = this[offset]; |
308 | 304 | if (val === undefined) |
309 | 305 | boundsError(offset, this.length - 1); |
@@ -329,7 +325,7 @@ function readIntBE(offset, byteLength) { |
329 | 325 | } |
330 | 326 |
|
331 | 327 | function readInt48BE(buf, offset = 0) { |
332 | | - checkNumberType(offset); |
| 328 | + validateNumber(offset, 'offset'); |
333 | 329 | const first = buf[offset]; |
334 | 330 | const last = buf[offset + 5]; |
335 | 331 | if (first === undefined || last === undefined) |
@@ -344,7 +340,7 @@ function readInt48BE(buf, offset = 0) { |
344 | 340 | } |
345 | 341 |
|
346 | 342 | function readInt40BE(buf, offset = 0) { |
347 | | - checkNumberType(offset); |
| 343 | + validateNumber(offset, 'offset'); |
348 | 344 | const first = buf[offset]; |
349 | 345 | const last = buf[offset + 4]; |
350 | 346 | if (first === undefined || last === undefined) |
@@ -358,7 +354,7 @@ function readInt40BE(buf, offset = 0) { |
358 | 354 | } |
359 | 355 |
|
360 | 356 | function readInt32BE(offset = 0) { |
361 | | - checkNumberType(offset); |
| 357 | + validateNumber(offset, 'offset'); |
362 | 358 | const first = this[offset]; |
363 | 359 | const last = this[offset + 3]; |
364 | 360 | if (first === undefined || last === undefined) |
@@ -371,7 +367,7 @@ function readInt32BE(offset = 0) { |
371 | 367 | } |
372 | 368 |
|
373 | 369 | function readInt24BE(buf, offset = 0) { |
374 | | - checkNumberType(offset); |
| 370 | + validateNumber(offset, 'offset'); |
375 | 371 | const first = buf[offset]; |
376 | 372 | const last = buf[offset + 2]; |
377 | 373 | if (first === undefined || last === undefined) |
@@ -382,7 +378,7 @@ function readInt24BE(buf, offset = 0) { |
382 | 378 | } |
383 | 379 |
|
384 | 380 | function readInt16BE(offset = 0) { |
385 | | - checkNumberType(offset); |
| 381 | + validateNumber(offset, 'offset'); |
386 | 382 | const first = this[offset]; |
387 | 383 | const last = this[offset + 1]; |
388 | 384 | if (first === undefined || last === undefined) |
@@ -394,7 +390,7 @@ function readInt16BE(offset = 0) { |
394 | 390 |
|
395 | 391 | // Read floats |
396 | 392 | function readFloatBackwards(offset = 0) { |
397 | | - checkNumberType(offset); |
| 393 | + validateNumber(offset, 'offset'); |
398 | 394 | const first = this[offset]; |
399 | 395 | const last = this[offset + 3]; |
400 | 396 | if (first === undefined || last === undefined) |
@@ -408,7 +404,7 @@ function readFloatBackwards(offset = 0) { |
408 | 404 | } |
409 | 405 |
|
410 | 406 | function readFloatForwards(offset = 0) { |
411 | | - checkNumberType(offset); |
| 407 | + validateNumber(offset, 'offset'); |
412 | 408 | const first = this[offset]; |
413 | 409 | const last = this[offset + 3]; |
414 | 410 | if (first === undefined || last === undefined) |
@@ -422,7 +418,7 @@ function readFloatForwards(offset = 0) { |
422 | 418 | } |
423 | 419 |
|
424 | 420 | function readDoubleBackwards(offset = 0) { |
425 | | - checkNumberType(offset); |
| 421 | + validateNumber(offset, 'offset'); |
426 | 422 | const first = this[offset]; |
427 | 423 | const last = this[offset + 7]; |
428 | 424 | if (first === undefined || last === undefined) |
@@ -440,7 +436,7 @@ function readDoubleBackwards(offset = 0) { |
440 | 436 | } |
441 | 437 |
|
442 | 438 | function readDoubleForwards(offset = 0) { |
443 | | - checkNumberType(offset); |
| 439 | + validateNumber(offset, 'offset'); |
444 | 440 | const first = this[offset]; |
445 | 441 | const last = this[offset + 7]; |
446 | 442 | if (first === undefined || last === undefined) |
@@ -554,7 +550,7 @@ function writeUInt16LE(value, offset = 0) { |
554 | 550 | function writeU_Int8(buf, value, offset, min, max) { |
555 | 551 | value = +value; |
556 | 552 | // `checkInt()` can not be used here because it checks two entries. |
557 | | - checkNumberType(offset); |
| 553 | + validateNumber(offset, 'offset'); |
558 | 554 | if (value > max || value < min) { |
559 | 555 | throw new ERR_OUT_OF_RANGE('value', `>= ${min} and <= ${max}`, value); |
560 | 556 | } |
|