@@ -646,6 +646,12 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
646646
647647 length |= 0 ;
648648
649+ if ( position == null ) {
650+ position = - 1 ;
651+ } else {
652+ validatePosition ( position , 'position' , length ) ;
653+ }
654+
649655 if ( length === 0 ) {
650656 return process . nextTick ( function tick ( ) {
651657 callback ( null , 0 , buffer ) ;
@@ -659,12 +665,6 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
659665
660666 validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
661667
662- if ( position == null ) {
663- position = - 1 ;
664- } else {
665- validatePosition ( position , 'position' , length ) ;
666- }
667-
668668 function wrapper ( err , bytesRead ) {
669669 // Retain a reference to buffer so that it can't be GC'ed too soon.
670670 callback ( err , bytesRead || 0 , buffer ) ;
@@ -717,6 +717,12 @@ function readSync(fd, buffer, offsetOrOptions, length, position) {
717717
718718 length |= 0 ;
719719
720+ if ( position == null ) {
721+ position = - 1 ;
722+ } else {
723+ validatePosition ( position , 'position' , length ) ;
724+ }
725+
720726 if ( length === 0 ) {
721727 return 0 ;
722728 }
@@ -728,12 +734,6 @@ function readSync(fd, buffer, offsetOrOptions, length, position) {
728734
729735 validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
730736
731- if ( position == null ) {
732- position = - 1 ;
733- } else {
734- validatePosition ( position , 'position' , length ) ;
735- }
736-
737737 return binding . read ( fd , buffer , offset , length , position ) ;
738738}
739739
0 commit comments