@@ -145,6 +145,12 @@ function isFd(path) {
145
145
146
146
fs . Stats = Stats ;
147
147
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
+
148
154
// Don't allow mode to accidentally be overwritten.
149
155
Object . defineProperties ( fs , {
150
156
F_OK : { enumerable : true , value : constants . F_OK || 0 } ,
@@ -317,10 +323,8 @@ function readFileAfterStat(err) {
317
323
if ( err )
318
324
return context . close ( err ) ;
319
325
320
- // Use stats array directly to avoid creating an fs.Stats instance just for
321
- // our internal use.
322
326
var size ;
323
- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFREG )
327
+ if ( isFileType ( S_IFREG ) )
324
328
size = context . size = statValues [ 8 ] ;
325
329
else
326
330
size = context . size = 0 ;
@@ -432,10 +436,8 @@ fs.readFileSync = function(path, options) {
432
436
var fd = isUserFd ? path : fs . openSync ( path , options . flag || 'r' , 0o666 ) ;
433
437
434
438
tryStatSync ( fd , isUserFd ) ;
435
- // Use stats array directly to avoid creating an fs.Stats instance just for
436
- // our internal use.
437
439
var size ;
438
- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) === S_IFREG )
440
+ if ( isFileType ( S_IFREG ) )
439
441
size = statValues [ 8 ] ;
440
442
else
441
443
size = 0 ;
@@ -1604,8 +1606,7 @@ fs.realpathSync = function realpathSync(p, options) {
1604
1606
1605
1607
// continue if not a symlink, break if a pipe/socket
1606
1608
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 ) ) {
1609
1610
break ;
1610
1611
}
1611
1612
continue ;
@@ -1624,7 +1625,7 @@ fs.realpathSync = function realpathSync(p, options) {
1624
1625
binding . lstat ( baseLong , undefined , ctx ) ;
1625
1626
handleErrorFromBinding ( ctx ) ;
1626
1627
1627
- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) !== S_IFLNK ) {
1628
+ if ( ! isFileType ( S_IFLNK ) ) {
1628
1629
knownHard [ base ] = true ;
1629
1630
if ( cache ) cache . set ( base , base ) ;
1630
1631
continue ;
@@ -1750,8 +1751,7 @@ fs.realpath = function realpath(p, options, callback) {
1750
1751
1751
1752
// continue if not a symlink, break if a pipe/socket
1752
1753
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 ) ) {
1755
1755
return callback ( null , encodeRealpathResult ( p , options ) ) ;
1756
1756
}
1757
1757
return process . nextTick ( LOOP ) ;
@@ -1767,7 +1767,7 @@ fs.realpath = function realpath(p, options, callback) {
1767
1767
// our internal use.
1768
1768
1769
1769
// if not a symlink, skip to the next path part
1770
- if ( ( statValues [ 1 /*mode*/ ] & S_IFMT ) !== S_IFLNK ) {
1770
+ if ( ! isFileType ( S_IFLNK ) ) {
1771
1771
knownHard [ base ] = true ;
1772
1772
return process . nextTick ( LOOP ) ;
1773
1773
}
0 commit comments