@@ -25,7 +25,7 @@ float32Array[0] = -1; // 0xBF800000
2525const bigEndian = uInt8Float32Array [ 3 ] === 0 ;
2626
2727function checkBounds ( buf , offset , byteLength ) {
28- checkNumberType ( offset ) ;
28+ validateNumber ( offset , 'offset' ) ;
2929 if ( buf [ offset ] === undefined || buf [ offset + byteLength ] === undefined )
3030 boundsError ( offset , buf . length - ( byteLength + 1 ) ) ;
3131}
@@ -37,13 +37,9 @@ function checkInt(value, min, max, buf, offset, byteLength) {
3737 checkBounds ( buf , offset , byteLength ) ;
3838}
3939
40- function checkNumberType ( value , type ) {
41- validateNumber ( value , type || 'offset' ) ;
42- }
43-
4440function boundsError ( value , length , type ) {
4541 if ( Math . floor ( value ) !== value ) {
46- checkNumberType ( value , type ) ;
42+ validateNumber ( value , type ) ;
4743 throw new ERR_OUT_OF_RANGE ( type || 'offset' , 'an integer' , value ) ;
4844 }
4945
@@ -74,7 +70,7 @@ function readUIntLE(offset, byteLength) {
7470}
7571
7672function readUInt48LE ( buf , offset = 0 ) {
77- checkNumberType ( offset ) ;
73+ validateNumber ( offset , 'offset' ) ;
7874 const first = buf [ offset ] ;
7975 const last = buf [ offset + 5 ] ;
8076 if ( first === undefined || last === undefined )
@@ -88,7 +84,7 @@ function readUInt48LE(buf, offset = 0) {
8884}
8985
9086function readUInt40LE ( buf , offset = 0 ) {
91- checkNumberType ( offset ) ;
87+ validateNumber ( offset , 'offset' ) ;
9288 const first = buf [ offset ] ;
9389 const last = buf [ offset + 4 ] ;
9490 if ( first === undefined || last === undefined )
@@ -102,7 +98,7 @@ function readUInt40LE(buf, offset = 0) {
10298}
10399
104100function readUInt32LE ( offset = 0 ) {
105- checkNumberType ( offset ) ;
101+ validateNumber ( offset , 'offset' ) ;
106102 const first = this [ offset ] ;
107103 const last = this [ offset + 3 ] ;
108104 if ( first === undefined || last === undefined )
@@ -115,7 +111,7 @@ function readUInt32LE(offset = 0) {
115111}
116112
117113function readUInt24LE ( buf , offset = 0 ) {
118- checkNumberType ( offset ) ;
114+ validateNumber ( offset , 'offset' ) ;
119115 const first = buf [ offset ] ;
120116 const last = buf [ offset + 2 ] ;
121117 if ( first === undefined || last === undefined )
@@ -125,7 +121,7 @@ function readUInt24LE(buf, offset = 0) {
125121}
126122
127123function readUInt16LE ( offset = 0 ) {
128- checkNumberType ( offset ) ;
124+ validateNumber ( offset , 'offset' ) ;
129125 const first = this [ offset ] ;
130126 const last = this [ offset + 1 ] ;
131127 if ( first === undefined || last === undefined )
@@ -135,7 +131,7 @@ function readUInt16LE(offset = 0) {
135131}
136132
137133function readUInt8 ( offset = 0 ) {
138- checkNumberType ( offset ) ;
134+ validateNumber ( offset , 'offset' ) ;
139135 const val = this [ offset ] ;
140136 if ( val === undefined )
141137 boundsError ( offset , this . length - 1 ) ;
@@ -161,7 +157,7 @@ function readUIntBE(offset, byteLength) {
161157}
162158
163159function readUInt48BE ( buf , offset = 0 ) {
164- checkNumberType ( offset ) ;
160+ validateNumber ( offset , 'offset' ) ;
165161 const first = buf [ offset ] ;
166162 const last = buf [ offset + 5 ] ;
167163 if ( first === undefined || last === undefined )
@@ -175,7 +171,7 @@ function readUInt48BE(buf, offset = 0) {
175171}
176172
177173function readUInt40BE ( buf , offset = 0 ) {
178- checkNumberType ( offset ) ;
174+ validateNumber ( offset , 'offset' ) ;
179175 const first = buf [ offset ] ;
180176 const last = buf [ offset + 4 ] ;
181177 if ( first === undefined || last === undefined )
@@ -189,7 +185,7 @@ function readUInt40BE(buf, offset = 0) {
189185}
190186
191187function readUInt32BE ( offset = 0 ) {
192- checkNumberType ( offset ) ;
188+ validateNumber ( offset , 'offset' ) ;
193189 const first = this [ offset ] ;
194190 const last = this [ offset + 3 ] ;
195191 if ( first === undefined || last === undefined )
@@ -202,7 +198,7 @@ function readUInt32BE(offset = 0) {
202198}
203199
204200function readUInt24BE ( buf , offset = 0 ) {
205- checkNumberType ( offset ) ;
201+ validateNumber ( offset , 'offset' ) ;
206202 const first = buf [ offset ] ;
207203 const last = buf [ offset + 2 ] ;
208204 if ( first === undefined || last === undefined )
@@ -212,7 +208,7 @@ function readUInt24BE(buf, offset = 0) {
212208}
213209
214210function readUInt16BE ( offset = 0 ) {
215- checkNumberType ( offset ) ;
211+ validateNumber ( offset , 'offset' ) ;
216212 const first = this [ offset ] ;
217213 const last = this [ offset + 1 ] ;
218214 if ( first === undefined || last === undefined )
@@ -239,7 +235,7 @@ function readIntLE(offset, byteLength) {
239235}
240236
241237function readInt48LE ( buf , offset = 0 ) {
242- checkNumberType ( offset ) ;
238+ validateNumber ( offset , 'offset' ) ;
243239 const first = buf [ offset ] ;
244240 const last = buf [ offset + 5 ] ;
245241 if ( first === undefined || last === undefined )
@@ -254,7 +250,7 @@ function readInt48LE(buf, offset = 0) {
254250}
255251
256252function readInt40LE ( buf , offset = 0 ) {
257- checkNumberType ( offset ) ;
253+ validateNumber ( offset , 'offset' ) ;
258254 const first = buf [ offset ] ;
259255 const last = buf [ offset + 4 ] ;
260256 if ( first === undefined || last === undefined )
@@ -268,7 +264,7 @@ function readInt40LE(buf, offset = 0) {
268264}
269265
270266function readInt32LE ( offset = 0 ) {
271- checkNumberType ( offset ) ;
267+ validateNumber ( offset , 'offset' ) ;
272268 const first = this [ offset ] ;
273269 const last = this [ offset + 3 ] ;
274270 if ( first === undefined || last === undefined )
@@ -281,7 +277,7 @@ function readInt32LE(offset = 0) {
281277}
282278
283279function readInt24LE ( buf , offset = 0 ) {
284- checkNumberType ( offset ) ;
280+ validateNumber ( offset , 'offset' ) ;
285281 const first = buf [ offset ] ;
286282 const last = buf [ offset + 2 ] ;
287283 if ( first === undefined || last === undefined )
@@ -292,7 +288,7 @@ function readInt24LE(buf, offset = 0) {
292288}
293289
294290function readInt16LE ( offset = 0 ) {
295- checkNumberType ( offset ) ;
291+ validateNumber ( offset , 'offset' ) ;
296292 const first = this [ offset ] ;
297293 const last = this [ offset + 1 ] ;
298294 if ( first === undefined || last === undefined )
@@ -303,7 +299,7 @@ function readInt16LE(offset = 0) {
303299}
304300
305301function readInt8 ( offset = 0 ) {
306- checkNumberType ( offset ) ;
302+ validateNumber ( offset , 'offset' ) ;
307303 const val = this [ offset ] ;
308304 if ( val === undefined )
309305 boundsError ( offset , this . length - 1 ) ;
@@ -329,7 +325,7 @@ function readIntBE(offset, byteLength) {
329325}
330326
331327function readInt48BE ( buf , offset = 0 ) {
332- checkNumberType ( offset ) ;
328+ validateNumber ( offset , 'offset' ) ;
333329 const first = buf [ offset ] ;
334330 const last = buf [ offset + 5 ] ;
335331 if ( first === undefined || last === undefined )
@@ -344,7 +340,7 @@ function readInt48BE(buf, offset = 0) {
344340}
345341
346342function readInt40BE ( buf , offset = 0 ) {
347- checkNumberType ( offset ) ;
343+ validateNumber ( offset , 'offset' ) ;
348344 const first = buf [ offset ] ;
349345 const last = buf [ offset + 4 ] ;
350346 if ( first === undefined || last === undefined )
@@ -358,7 +354,7 @@ function readInt40BE(buf, offset = 0) {
358354}
359355
360356function readInt32BE ( offset = 0 ) {
361- checkNumberType ( offset ) ;
357+ validateNumber ( offset , 'offset' ) ;
362358 const first = this [ offset ] ;
363359 const last = this [ offset + 3 ] ;
364360 if ( first === undefined || last === undefined )
@@ -371,7 +367,7 @@ function readInt32BE(offset = 0) {
371367}
372368
373369function readInt24BE ( buf , offset = 0 ) {
374- checkNumberType ( offset ) ;
370+ validateNumber ( offset , 'offset' ) ;
375371 const first = buf [ offset ] ;
376372 const last = buf [ offset + 2 ] ;
377373 if ( first === undefined || last === undefined )
@@ -382,7 +378,7 @@ function readInt24BE(buf, offset = 0) {
382378}
383379
384380function readInt16BE ( offset = 0 ) {
385- checkNumberType ( offset ) ;
381+ validateNumber ( offset , 'offset' ) ;
386382 const first = this [ offset ] ;
387383 const last = this [ offset + 1 ] ;
388384 if ( first === undefined || last === undefined )
@@ -394,7 +390,7 @@ function readInt16BE(offset = 0) {
394390
395391// Read floats
396392function readFloatBackwards ( offset = 0 ) {
397- checkNumberType ( offset ) ;
393+ validateNumber ( offset , 'offset' ) ;
398394 const first = this [ offset ] ;
399395 const last = this [ offset + 3 ] ;
400396 if ( first === undefined || last === undefined )
@@ -408,7 +404,7 @@ function readFloatBackwards(offset = 0) {
408404}
409405
410406function readFloatForwards ( offset = 0 ) {
411- checkNumberType ( offset ) ;
407+ validateNumber ( offset , 'offset' ) ;
412408 const first = this [ offset ] ;
413409 const last = this [ offset + 3 ] ;
414410 if ( first === undefined || last === undefined )
@@ -422,7 +418,7 @@ function readFloatForwards(offset = 0) {
422418}
423419
424420function readDoubleBackwards ( offset = 0 ) {
425- checkNumberType ( offset ) ;
421+ validateNumber ( offset , 'offset' ) ;
426422 const first = this [ offset ] ;
427423 const last = this [ offset + 7 ] ;
428424 if ( first === undefined || last === undefined )
@@ -440,7 +436,7 @@ function readDoubleBackwards(offset = 0) {
440436}
441437
442438function readDoubleForwards ( offset = 0 ) {
443- checkNumberType ( offset ) ;
439+ validateNumber ( offset , 'offset' ) ;
444440 const first = this [ offset ] ;
445441 const last = this [ offset + 7 ] ;
446442 if ( first === undefined || last === undefined )
@@ -554,7 +550,7 @@ function writeUInt16LE(value, offset = 0) {
554550function writeU_Int8 ( buf , value , offset , min , max ) {
555551 value = + value ;
556552 // `checkInt()` can not be used here because it checks two entries.
557- checkNumberType ( offset ) ;
553+ validateNumber ( offset , 'offset' ) ;
558554 if ( value > max || value < min ) {
559555 throw new ERR_OUT_OF_RANGE ( 'value' , `>= ${ min } and <= ${ max } ` , value ) ;
560556 }
0 commit comments