@@ -145,6 +145,12 @@ function isFd(path) {
145145
146146fs . Stats = Stats ;
147147
148+ function isFileType ( fileType ) {
149+ // Use stats array directly to avoid creating an fs.Stats instance just for
150+ // our internal use.
151+ return ( statValues [ 1 /*mode*/ ] & S_IFMT ) === fileType ;
152+ }
153+
148154// Don't allow mode to accidentally be overwritten.
149155Object . defineProperties ( fs , {
150156 F_OK : { enumerable : true , value : constants . F_OK || 0 } ,
@@ -317,10 +323,8 @@ function readFileAfterStat(err) {
317323 if ( err )
318324 return context . close ( err ) ;
319325
320- // Use stats array directly to avoid creating an fs.Stats instance just for
321- // our internal use.
322326 var size ;
323- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFREG )
327+ if ( isFileType ( S_IFREG ) )
324328 size = context . size = statValues [ 8 ] ;
325329 else
326330 size = context . size = 0 ;
@@ -432,10 +436,8 @@ fs.readFileSync = function(path, options) {
432436 var fd = isUserFd ? path : fs . openSync ( path , options . flag || 'r' , 0o666 ) ;
433437
434438 tryStatSync ( fd , isUserFd ) ;
435- // Use stats array directly to avoid creating an fs.Stats instance just for
436- // our internal use.
437439 var size ;
438- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFREG )
440+ if ( isFileType ( S_IFREG ) )
439441 size = statValues [ 8 ] ;
440442 else
441443 size = 0 ;
@@ -1604,8 +1606,7 @@ fs.realpathSync = function realpathSync(p, options) {
16041606
16051607 // continue if not a symlink, break if a pipe/socket
16061608 if ( knownHard [ base ] || ( cache && cache . get ( base ) === base ) ) {
1607- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFIFO ||
1608- ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFSOCK ) {
1609+ if ( isFileType ( S_IFIFO ) || isFileType ( S_IFSOCK ) ) {
16091610 break ;
16101611 }
16111612 continue ;
@@ -1624,7 +1625,7 @@ fs.realpathSync = function realpathSync(p, options) {
16241625 binding . lstat ( baseLong , undefined , ctx ) ;
16251626 handleErrorFromBinding ( ctx ) ;
16261627
1627- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) !== S_IFLNK ) {
1628+ if ( ! isFileType ( S_IFLNK ) ) {
16281629 knownHard [ base ] = true ;
16291630 if ( cache ) cache . set ( base , base ) ;
16301631 continue ;
@@ -1750,8 +1751,7 @@ fs.realpath = function realpath(p, options, callback) {
17501751
17511752 // continue if not a symlink, break if a pipe/socket
17521753 if ( knownHard [ base ] ) {
1753- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFIFO ||
1754- ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFSOCK ) {
1754+ if ( isFileType ( S_IFIFO ) || isFileType ( S_IFSOCK ) ) {
17551755 return callback ( null , encodeRealpathResult ( p , options ) ) ;
17561756 }
17571757 return process . nextTick ( LOOP ) ;
@@ -1767,7 +1767,7 @@ fs.realpath = function realpath(p, options, callback) {
17671767 // our internal use.
17681768
17691769 // if not a symlink, skip to the next path part
1770- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) !== S_IFLNK ) {
1770+ if ( ! isFileType ( S_IFLNK ) ) {
17711771 knownHard [ base ] = true ;
17721772 return process . nextTick ( LOOP ) ;
17731773 }
0 commit comments