@@ -26,7 +26,7 @@ float32Array[0] = -1; // 0xBF800000
2626const bigEndian = uInt8Float32Array [ 3 ] === 0 ;
2727
2828function checkBounds ( buf , offset , byteLength ) {
29- checkNumberType ( offset ) ;
29+ validateNumber ( offset , 'offset' ) ;
3030 if ( buf [ offset ] === undefined || buf [ offset + byteLength ] === undefined )
3131 boundsError ( offset , buf . length - ( byteLength + 1 ) ) ;
3232}
@@ -38,13 +38,9 @@ function checkInt(value, min, max, buf, offset, byteLength) {
3838 checkBounds ( buf , offset , byteLength ) ;
3939}
4040
41- function checkNumberType ( value , type ) {
42- validateNumber ( value , type || 'offset' ) ;
43- }
44-
4541function boundsError ( value , length , type ) {
4642 if ( Math . floor ( value ) !== value ) {
47- checkNumberType ( value , type ) ;
43+ validateNumber ( value , type ) ;
4844 throw new ERR_OUT_OF_RANGE ( type || 'offset' , 'an integer' , value ) ;
4945 }
5046
@@ -77,7 +73,7 @@ function readUIntLE(offset, byteLength) {
7773}
7874
7975function readUInt48LE ( buf , offset = 0 ) {
80- checkNumberType ( offset ) ;
76+ validateNumber ( offset , 'offset' ) ;
8177 const first = buf [ offset ] ;
8278 const last = buf [ offset + 5 ] ;
8379 if ( first === undefined || last === undefined )
@@ -91,7 +87,7 @@ function readUInt48LE(buf, offset = 0) {
9187}
9288
9389function readUInt40LE ( buf , offset = 0 ) {
94- checkNumberType ( offset ) ;
90+ validateNumber ( offset , 'offset' ) ;
9591 const first = buf [ offset ] ;
9692 const last = buf [ offset + 4 ] ;
9793 if ( first === undefined || last === undefined )
@@ -105,7 +101,7 @@ function readUInt40LE(buf, offset = 0) {
105101}
106102
107103function readUInt32LE ( offset = 0 ) {
108- checkNumberType ( offset ) ;
104+ validateNumber ( offset , 'offset' ) ;
109105 const first = this [ offset ] ;
110106 const last = this [ offset + 3 ] ;
111107 if ( first === undefined || last === undefined )
@@ -118,7 +114,7 @@ function readUInt32LE(offset = 0) {
118114}
119115
120116function readUInt24LE ( buf , offset = 0 ) {
121- checkNumberType ( offset ) ;
117+ validateNumber ( offset , 'offset' ) ;
122118 const first = buf [ offset ] ;
123119 const last = buf [ offset + 2 ] ;
124120 if ( first === undefined || last === undefined )
@@ -128,7 +124,7 @@ function readUInt24LE(buf, offset = 0) {
128124}
129125
130126function readUInt16LE ( offset = 0 ) {
131- checkNumberType ( offset ) ;
127+ validateNumber ( offset , 'offset' ) ;
132128 const first = this [ offset ] ;
133129 const last = this [ offset + 1 ] ;
134130 if ( first === undefined || last === undefined )
@@ -138,7 +134,7 @@ function readUInt16LE(offset = 0) {
138134}
139135
140136function readUInt8 ( offset = 0 ) {
141- checkNumberType ( offset ) ;
137+ validateNumber ( offset , 'offset' ) ;
142138 const val = this [ offset ] ;
143139 if ( val === undefined )
144140 boundsError ( offset , this . length - 1 ) ;
@@ -166,7 +162,7 @@ function readUIntBE(offset, byteLength) {
166162}
167163
168164function readUInt48BE ( buf , offset = 0 ) {
169- checkNumberType ( offset ) ;
165+ validateNumber ( offset , 'offset' ) ;
170166 const first = buf [ offset ] ;
171167 const last = buf [ offset + 5 ] ;
172168 if ( first === undefined || last === undefined )
@@ -180,7 +176,7 @@ function readUInt48BE(buf, offset = 0) {
180176}
181177
182178function readUInt40BE ( buf , offset = 0 ) {
183- checkNumberType ( offset ) ;
179+ validateNumber ( offset , 'offset' ) ;
184180 const first = buf [ offset ] ;
185181 const last = buf [ offset + 4 ] ;
186182 if ( first === undefined || last === undefined )
@@ -194,7 +190,7 @@ function readUInt40BE(buf, offset = 0) {
194190}
195191
196192function readUInt32BE ( offset = 0 ) {
197- checkNumberType ( offset ) ;
193+ validateNumber ( offset , 'offset' ) ;
198194 const first = this [ offset ] ;
199195 const last = this [ offset + 3 ] ;
200196 if ( first === undefined || last === undefined )
@@ -207,7 +203,7 @@ function readUInt32BE(offset = 0) {
207203}
208204
209205function readUInt24BE ( buf , offset = 0 ) {
210- checkNumberType ( offset ) ;
206+ validateNumber ( offset , 'offset' ) ;
211207 const first = buf [ offset ] ;
212208 const last = buf [ offset + 2 ] ;
213209 if ( first === undefined || last === undefined )
@@ -217,7 +213,7 @@ function readUInt24BE(buf, offset = 0) {
217213}
218214
219215function readUInt16BE ( offset = 0 ) {
220- checkNumberType ( offset ) ;
216+ validateNumber ( offset , 'offset' ) ;
221217 const first = this [ offset ] ;
222218 const last = this [ offset + 1 ] ;
223219 if ( first === undefined || last === undefined )
@@ -246,7 +242,7 @@ function readIntLE(offset, byteLength) {
246242}
247243
248244function readInt48LE ( buf , offset = 0 ) {
249- checkNumberType ( offset ) ;
245+ validateNumber ( offset , 'offset' ) ;
250246 const first = buf [ offset ] ;
251247 const last = buf [ offset + 5 ] ;
252248 if ( first === undefined || last === undefined )
@@ -261,7 +257,7 @@ function readInt48LE(buf, offset = 0) {
261257}
262258
263259function readInt40LE ( buf , offset = 0 ) {
264- checkNumberType ( offset ) ;
260+ validateNumber ( offset , 'offset' ) ;
265261 const first = buf [ offset ] ;
266262 const last = buf [ offset + 4 ] ;
267263 if ( first === undefined || last === undefined )
@@ -275,7 +271,7 @@ function readInt40LE(buf, offset = 0) {
275271}
276272
277273function readInt32LE ( offset = 0 ) {
278- checkNumberType ( offset ) ;
274+ validateNumber ( offset , 'offset' ) ;
279275 const first = this [ offset ] ;
280276 const last = this [ offset + 3 ] ;
281277 if ( first === undefined || last === undefined )
@@ -288,7 +284,7 @@ function readInt32LE(offset = 0) {
288284}
289285
290286function readInt24LE ( buf , offset = 0 ) {
291- checkNumberType ( offset ) ;
287+ validateNumber ( offset , 'offset' ) ;
292288 const first = buf [ offset ] ;
293289 const last = buf [ offset + 2 ] ;
294290 if ( first === undefined || last === undefined )
@@ -299,7 +295,7 @@ function readInt24LE(buf, offset = 0) {
299295}
300296
301297function readInt16LE ( offset = 0 ) {
302- checkNumberType ( offset ) ;
298+ validateNumber ( offset , 'offset' ) ;
303299 const first = this [ offset ] ;
304300 const last = this [ offset + 1 ] ;
305301 if ( first === undefined || last === undefined )
@@ -310,7 +306,7 @@ function readInt16LE(offset = 0) {
310306}
311307
312308function readInt8 ( offset = 0 ) {
313- checkNumberType ( offset ) ;
309+ validateNumber ( offset , 'offset' ) ;
314310 const val = this [ offset ] ;
315311 if ( val === undefined )
316312 boundsError ( offset , this . length - 1 ) ;
@@ -338,7 +334,7 @@ function readIntBE(offset, byteLength) {
338334}
339335
340336function readInt48BE ( buf , offset = 0 ) {
341- checkNumberType ( offset ) ;
337+ validateNumber ( offset , 'offset' ) ;
342338 const first = buf [ offset ] ;
343339 const last = buf [ offset + 5 ] ;
344340 if ( first === undefined || last === undefined )
@@ -353,7 +349,7 @@ function readInt48BE(buf, offset = 0) {
353349}
354350
355351function readInt40BE ( buf , offset = 0 ) {
356- checkNumberType ( offset ) ;
352+ validateNumber ( offset , 'offset' ) ;
357353 const first = buf [ offset ] ;
358354 const last = buf [ offset + 4 ] ;
359355 if ( first === undefined || last === undefined )
@@ -367,7 +363,7 @@ function readInt40BE(buf, offset = 0) {
367363}
368364
369365function readInt32BE ( offset = 0 ) {
370- checkNumberType ( offset ) ;
366+ validateNumber ( offset , 'offset' ) ;
371367 const first = this [ offset ] ;
372368 const last = this [ offset + 3 ] ;
373369 if ( first === undefined || last === undefined )
@@ -380,7 +376,7 @@ function readInt32BE(offset = 0) {
380376}
381377
382378function readInt24BE ( buf , offset = 0 ) {
383- checkNumberType ( offset ) ;
379+ validateNumber ( offset , 'offset' ) ;
384380 const first = buf [ offset ] ;
385381 const last = buf [ offset + 2 ] ;
386382 if ( first === undefined || last === undefined )
@@ -391,7 +387,7 @@ function readInt24BE(buf, offset = 0) {
391387}
392388
393389function readInt16BE ( offset = 0 ) {
394- checkNumberType ( offset ) ;
390+ validateNumber ( offset , 'offset' ) ;
395391 const first = this [ offset ] ;
396392 const last = this [ offset + 1 ] ;
397393 if ( first === undefined || last === undefined )
@@ -403,7 +399,7 @@ function readInt16BE(offset = 0) {
403399
404400// Read floats
405401function readFloatBackwards ( offset = 0 ) {
406- checkNumberType ( offset ) ;
402+ validateNumber ( offset , 'offset' ) ;
407403 const first = this [ offset ] ;
408404 const last = this [ offset + 3 ] ;
409405 if ( first === undefined || last === undefined )
@@ -417,7 +413,7 @@ function readFloatBackwards(offset = 0) {
417413}
418414
419415function readFloatForwards ( offset = 0 ) {
420- checkNumberType ( offset ) ;
416+ validateNumber ( offset , 'offset' ) ;
421417 const first = this [ offset ] ;
422418 const last = this [ offset + 3 ] ;
423419 if ( first === undefined || last === undefined )
@@ -431,7 +427,7 @@ function readFloatForwards(offset = 0) {
431427}
432428
433429function readDoubleBackwards ( offset = 0 ) {
434- checkNumberType ( offset ) ;
430+ validateNumber ( offset , 'offset' ) ;
435431 const first = this [ offset ] ;
436432 const last = this [ offset + 7 ] ;
437433 if ( first === undefined || last === undefined )
@@ -449,7 +445,7 @@ function readDoubleBackwards(offset = 0) {
449445}
450446
451447function readDoubleForwards ( offset = 0 ) {
452- checkNumberType ( offset ) ;
448+ validateNumber ( offset , 'offset' ) ;
453449 const first = this [ offset ] ;
454450 const last = this [ offset + 7 ] ;
455451 if ( first === undefined || last === undefined )
@@ -563,7 +559,7 @@ function writeUInt16LE(value, offset = 0) {
563559function writeU_Int8 ( buf , value , offset , min , max ) {
564560 value = + value ;
565561 // `checkInt()` can not be used here because it checks two entries.
566- checkNumberType ( offset ) ;
562+ validateNumber ( offset , 'offset' ) ;
567563 if ( value > max || value < min ) {
568564 throw new ERR_OUT_OF_RANGE ( 'value' , `>= ${ min } and <= ${ max } ` , value ) ;
569565 }
0 commit comments