@@ -179,6 +179,12 @@ function isFd(path) {
179179
180180fs . Stats = Stats ;
181181
182+ function isFileType ( fileType ) {
183+ // Use stats array directly to avoid creating an fs.Stats instance just for
184+ // our internal use.
185+ return ( statValues [ 1 /*mode*/ ] & S_IFMT ) === fileType ;
186+ }
187+
182188// Don't allow mode to accidentally be overwritten.
183189Object . defineProperties ( fs , {
184190 F_OK : { enumerable : true , value : constants . F_OK || 0 } ,
@@ -371,10 +377,8 @@ function readFileAfterStat(err) {
371377 if ( err )
372378 return context . close ( err ) ;
373379
374- // Use stats array directly to avoid creating an fs.Stats instance just for
375- // our internal use.
376380 var size ;
377- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFREG )
381+ if ( isFileType ( S_IFREG ) )
378382 size = context . size = statValues [ 8 ] ;
379383 else
380384 size = context . size = 0 ;
@@ -486,10 +490,8 @@ fs.readFileSync = function(path, options) {
486490 var fd = isUserFd ? path : fs . openSync ( path , options . flag || 'r' , 0o666 ) ;
487491
488492 tryStatSync ( fd , isUserFd ) ;
489- // Use stats array directly to avoid creating an fs.Stats instance just for
490- // our internal use.
491493 var size ;
492- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFREG )
494+ if ( isFileType ( S_IFREG ) )
493495 size = statValues [ 8 ] ;
494496 else
495497 size = 0 ;
@@ -1623,8 +1625,7 @@ fs.realpathSync = function realpathSync(p, options) {
16231625
16241626 // continue if not a symlink, break if a pipe/socket
16251627 if ( knownHard [ base ] || ( cache && cache . get ( base ) === base ) ) {
1626- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFIFO ||
1627- ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFSOCK ) {
1628+ if ( isFileType ( S_IFIFO ) || isFileType ( S_IFSOCK ) ) {
16281629 break ;
16291630 }
16301631 continue ;
@@ -1643,7 +1644,7 @@ fs.realpathSync = function realpathSync(p, options) {
16431644 binding . lstat ( baseLong , undefined , ctx ) ;
16441645 handleErrorFromBinding ( ctx ) ;
16451646
1646- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) !== S_IFLNK ) {
1647+ if ( ! isFileType ( S_IFLNK ) ) {
16471648 knownHard [ base ] = true ;
16481649 if ( cache ) cache . set ( base , base ) ;
16491650 continue ;
@@ -1766,8 +1767,7 @@ fs.realpath = function realpath(p, options, callback) {
17661767
17671768 // continue if not a symlink, break if a pipe/socket
17681769 if ( knownHard [ base ] ) {
1769- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFIFO ||
1770- ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFSOCK ) {
1770+ if ( isFileType ( S_IFIFO ) || isFileType ( S_IFSOCK ) ) {
17711771 return callback ( null , encodeRealpathResult ( p , options ) ) ;
17721772 }
17731773 return process . nextTick ( LOOP ) ;
@@ -1783,7 +1783,7 @@ fs.realpath = function realpath(p, options, callback) {
17831783 // our internal use.
17841784
17851785 // if not a symlink, skip to the next path part
1786- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) !== S_IFLNK ) {
1786+ if ( ! isFileType ( S_IFLNK ) ) {
17871787 knownHard [ base ] = true ;
17881788 return process . nextTick ( LOOP ) ;
17891789 }
0 commit comments