@@ -69,7 +69,6 @@ const {
6969 ERR_INVALID_ARG_TYPE ,
7070 ERR_INVALID_CALLBACK ,
7171 ERR_FEATURE_UNAVAILABLE_ON_PLATFORM ,
72- ERR_OUT_OF_RANGE ,
7372 } ,
7473 hideStackFrames,
7574 uvErrmapGet,
@@ -99,6 +98,7 @@ const {
9998 validateOffsetLengthRead,
10099 validateOffsetLengthWrite,
101100 validatePath,
101+ validatePosition,
102102 validateRmOptions,
103103 validateRmOptionsSync,
104104 validateRmdirOptions,
@@ -556,19 +556,7 @@ function read(fd, buffer, offset, length, position, callback) {
556556 if ( position == null )
557557 position = - 1 ;
558558
559- if ( typeof position === 'number' ) {
560- validateInteger ( position , 'position' ) ;
561- } else if ( typeof position === 'bigint' ) {
562- if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
563- throw new ERR_OUT_OF_RANGE ( 'position' ,
564- `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
565- position ) ;
566- }
567- } else {
568- throw new ERR_INVALID_ARG_TYPE ( 'position' ,
569- [ 'integer' , 'bigint' ] ,
570- position ) ;
571- }
559+ validatePosition ( position , 'position' ) ;
572560
573561 function wrapper ( err , bytesRead ) {
574562 // Retain a reference to buffer so that it can't be GC'ed too soon.
@@ -622,19 +610,7 @@ function readSync(fd, buffer, offset, length, position) {
622610 if ( position == null )
623611 position = - 1 ;
624612
625- if ( typeof position === 'number' ) {
626- validateInteger ( position , 'position' ) ;
627- } else if ( typeof position === 'bigint' ) {
628- if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
629- throw new ERR_OUT_OF_RANGE ( 'position' ,
630- `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
631- position ) ;
632- }
633- } else {
634- throw new ERR_INVALID_ARG_TYPE ( 'position' ,
635- [ 'integer' , 'bigint' ] ,
636- position ) ;
637- }
613+ validatePosition ( position , 'position' ) ;
638614
639615 const ctx = { } ;
640616 const result = binding . read ( fd , buffer , offset , length , position ,
0 commit comments