@@ -75,7 +75,6 @@ const {
7575 ERR_INVALID_ARG_VALUE ,
7676 ERR_INVALID_ARG_TYPE ,
7777 ERR_FEATURE_UNAVAILABLE_ON_PLATFORM ,
78- ERR_OUT_OF_RANGE ,
7978 } ,
8079 hideStackFrames,
8180 uvErrmapGet,
@@ -105,6 +104,7 @@ const {
105104 validateOffsetLengthRead,
106105 validateOffsetLengthWrite,
107106 validatePath,
107+ validatePosition,
108108 validateRmOptions,
109109 validateRmOptionsSync,
110110 validateRmdirOptions,
@@ -550,19 +550,7 @@ function read(fd, buffer, offset, length, position, callback) {
550550 if ( position == null )
551551 position = - 1 ;
552552
553- if ( typeof position === 'number' ) {
554- validateInteger ( position , 'position' ) ;
555- } else if ( typeof position === 'bigint' ) {
556- if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
557- throw new ERR_OUT_OF_RANGE ( 'position' ,
558- `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
559- position ) ;
560- }
561- } else {
562- throw new ERR_INVALID_ARG_TYPE ( 'position' ,
563- [ 'integer' , 'bigint' ] ,
564- position ) ;
565- }
553+ validatePosition ( position , 'position' ) ;
566554
567555 function wrapper ( err , bytesRead ) {
568556 // Retain a reference to buffer so that it can't be GC'ed too soon.
@@ -616,19 +604,7 @@ function readSync(fd, buffer, offset, length, position) {
616604 if ( position == null )
617605 position = - 1 ;
618606
619- if ( typeof position === 'number' ) {
620- validateInteger ( position , 'position' ) ;
621- } else if ( typeof position === 'bigint' ) {
622- if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
623- throw new ERR_OUT_OF_RANGE ( 'position' ,
624- `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
625- position ) ;
626- }
627- } else {
628- throw new ERR_INVALID_ARG_TYPE ( 'position' ,
629- [ 'integer' , 'bigint' ] ,
630- position ) ;
631- }
607+ validatePosition ( position , 'position' ) ;
632608
633609 const ctx = { } ;
634610 const result = binding . read ( fd , buffer , offset , length , position ,
0 commit comments