@ -57,14 +57,14 @@ function rethrow() {
}
function maybeCallback ( cb ) {
return util . isFunction ( cb ) ? cb : rethrow ( ) ;
return typeof cb === 'function' ? cb : rethrow ( ) ;
}
// Ensure that callbacks run in the global context. Only use this function
// for callbacks that are passed to the binding layer, callbacks that are
// invoked from JS already run in the proper scope.
function makeCallback ( cb ) {
if ( ! util . isFunction ( cb ) ) {
if ( typeof cb !== 'function' ) {
return rethrow ( ) ;
}
@ -218,11 +218,11 @@ fs.existsSync = function(path) {
fs . readFile = function ( path , options , callback_ ) {
var callback = maybeCallback ( arguments [ arguments . length - 1 ] ) ;
if ( util . isFunction ( options ) || ! options ) {
if ( ! options || typeof options === 'function' ) {
options = { encoding : null , flag : 'r' } ;
} else if ( util . isString ( options ) ) {
} else if ( typeof options === 'string' ) {
options = { encoding : options , flag : 'r' } ;
} else if ( ! util . isObject ( options ) ) {
} else if ( typeof options !== 'object' ) {
throw new TypeError ( 'Bad arguments' ) ;
}
@ -317,9 +317,9 @@ fs.readFile = function(path, options, callback_) {
fs . readFileSync = function ( path , options ) {
if ( ! options ) {
options = { encoding : null , flag : 'r' } ;
} else if ( util . isString ( options ) ) {
} else if ( typeof options === 'string' ) {
options = { encoding : options , flag : 'r' } ;
} else if ( ! util . isObject ( options ) ) {
} else if ( typeof options !== 'object' ) {
throw new TypeError ( 'Bad arguments' ) ;
}
@ -395,7 +395,7 @@ fs.readFileSync = function(path, options) {
// Used by binding.open and friends
function stringToFlags ( flag ) {
// Only mess with strings
if ( ! util . isString ( flag ) ) {
if ( typeof flag !== 'string' ) {
return flag ;
}
@ -448,9 +448,9 @@ fs.closeSync = function(fd) {
} ;
function modeNum ( m , def ) {
if ( util . isNumber ( m ) )
if ( typeof m === 'number' )
return m ;
if ( util . isString ( m ) )
if ( typeof m === 'string' )
return parseInt ( m , 8 ) ;
if ( def )
return modeNum ( def ) ;
@ -479,7 +479,7 @@ fs.openSync = function(path, flags, mode) {
} ;
fs . read = function ( fd , buffer , offset , length , position , callback ) {
if ( ! util . isBuffer ( b uffer) ) {
if ( ! ( buffer instanceof B uffer) ) {
// legacy string interface (fd, length, position, encoding, callback)
var cb = arguments [ 4 ] ,
encoding = arguments [ 3 ] ;
@ -513,7 +513,7 @@ fs.read = function(fd, buffer, offset, length, position, callback) {
fs . readSync = function ( fd , buffer , offset , length , position ) {
var legacy = false ;
if ( ! util . isBuffer ( b uffer) ) {
if ( ! ( buffer instanceof B uffer) ) {
// legacy string interface (fd, length, position, encoding, callback)
legacy = true ;
var encoding = arguments [ 3 ] ;
@ -551,9 +551,9 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
callback ( err , written || 0 , buffer ) ;
}
if ( util . isBuffer ( buffer ) ) {
if ( buffer instanceof Buffer ) {
// if no position is passed then assume null
if ( util . isFunction ( position ) ) {
if ( typeof position === 'function' ) {
callback = position ;
position = null ;
}
@ -563,10 +563,10 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
return binding . writeBuffer ( fd , buffer , offset , length , position , req ) ;
}
if ( util . isString ( buffer ) )
if ( typeof buffer === 'string' )
buffer += '' ;
if ( ! util . isFunction ( position ) ) {
if ( util . isFunction ( offset ) ) {
if ( typeof position !== 'function' ) {
if ( typeof offset === 'function' ) {
position = offset ;
offset = null ;
} else {
@ -585,14 +585,14 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
// OR
// fs.writeSync(fd, string[, position[, encoding]]);
fs . writeSync = function ( fd , buffer , offset , length , position ) {
if ( util . isBuffer ( buffer ) ) {
if ( util . isUndefined ( position ) )
if ( buffer instanceof Buffer ) {
if ( position === undefined )
position = null ;
return binding . writeBuffer ( fd , buffer , offset , length , position ) ;
}
if ( ! util . isString ( buffer ) )
if ( typeof buffer !== 'string' )
buffer += '' ;
if ( util . isUndefined ( offset ) )
if ( offset === undefined )
offset = null ;
return binding . writeString ( fd , buffer , offset , length , position ) ;
} ;
@ -616,15 +616,15 @@ fs.renameSync = function(oldPath, newPath) {
} ;
fs . truncate = function ( path , len , callback ) {
if ( util . isNumber ( path ) ) {
if ( typeof path === 'number' ) {
var req = new FSReqWrap ( ) ;
req . oncomplete = callback ;
return fs . ftruncate ( path , len , req ) ;
}
if ( util . isFunction ( len ) ) {
if ( typeof len === 'function' ) {
callback = len ;
len = 0 ;
} else if ( util . isUndefined ( len ) ) {
} else if ( len === undefined ) {
len = 0 ;
}
@ -642,11 +642,11 @@ fs.truncate = function(path, len, callback) {
} ;
fs . truncateSync = function ( path , len ) {
if ( util . isNumber ( path ) ) {
if ( typeof path === 'number' ) {
// legacy
return fs . ftruncateSync ( path , len ) ;
}
if ( util . isUndefined ( len ) ) {
if ( len === undefined ) {
len = 0 ;
}
// allow error to be thrown, but still close fd.
@ -660,10 +660,10 @@ fs.truncateSync = function(path, len) {
} ;
fs . ftruncate = function ( fd , len , callback ) {
if ( util . isFunction ( len ) ) {
if ( typeof len === 'function' ) {
callback = len ;
len = 0 ;
} else if ( util . isUndefined ( len ) ) {
} else if ( len === undefined ) {
len = 0 ;
}
var req = new FSReqWrap ( ) ;
@ -672,7 +672,7 @@ fs.ftruncate = function(fd, len, callback) {
} ;
fs . ftruncateSync = function ( fd , len ) {
if ( util . isUndefined ( len ) ) {
if ( len === undefined ) {
len = 0 ;
}
return binding . ftruncate ( fd , len ) ;
@ -712,7 +712,7 @@ fs.fsyncSync = function(fd) {
} ;
fs . mkdir = function ( path , mode , callback ) {
if ( util . isFunction ( mode ) ) callback = mode ;
if ( typeof mode === 'function' ) callback = mode ;
callback = makeCallback ( callback ) ;
if ( ! nullCheck ( path , callback ) ) return ;
var req = new FSReqWrap ( ) ;
@ -806,7 +806,7 @@ function preprocessSymlinkDestination(path, type, linkPath) {
}
fs . symlink = function ( destination , path , type_ , callback ) {
var type = ( util . isString ( type_ ) ? type_ : null ) ;
var type = ( typeof type_ === 'string' ? type_ : null ) ;
var callback = makeCallback ( arguments [ arguments . length - 1 ] ) ;
if ( ! nullCheck ( destination , callback ) ) return ;
@ -822,7 +822,7 @@ fs.symlink = function(destination, path, type_, callback) {
} ;
fs . symlinkSync = function ( destination , path , type ) {
type = ( util . isString ( type ) ? type : null ) ;
type = ( typeof type === 'string' ? type : null ) ;
nullCheck ( destination ) ;
nullCheck ( path ) ;
@ -973,7 +973,7 @@ fs.chownSync = function(path, uid, gid) {
// converts Date or number to a fractional UNIX timestamp
function toUnixTimestamp ( time ) {
if ( util . isNumber ( time ) ) {
if ( typeof time === 'number' ) {
return time ;
}
if ( util . isDate ( time ) ) {
@ -1043,11 +1043,11 @@ function writeAll(fd, buffer, offset, length, position, callback) {
fs . writeFile = function ( path , data , options , callback ) {
var callback = maybeCallback ( arguments [ arguments . length - 1 ] ) ;
if ( util . isFunction ( options ) || ! options ) {
if ( ! options || typeof options === 'function' ) {
options = { encoding : 'utf8' , mode : 0o666 , flag : 'w' } ;
} else if ( util . isString ( options ) ) {
} else if ( typeof options === 'string' ) {
options = { encoding : options , mode : 0o666 , flag : 'w' } ;
} else if ( ! util . isObject ( options ) ) {
} else if ( typeof options !== 'object' ) {
throw new TypeError ( 'Bad arguments' ) ;
}
@ -1058,7 +1058,7 @@ fs.writeFile = function(path, data, options, callback) {
if ( openErr ) {
if ( callback ) callback ( openErr ) ;
} else {
var buffer = util . isBuffer ( data ) ? data : new Buffer ( '' + data ,
var buffer = ( data instanceof Buffer ) ? data : new Buffer ( '' + data ,
options . encoding || 'utf8' ) ;
var position = /a/ . test ( flag ) ? null : 0 ;
writeAll ( fd , buffer , 0 , buffer . length , position , callback ) ;
@ -1069,9 +1069,9 @@ fs.writeFile = function(path, data, options, callback) {
fs . writeFileSync = function ( path , data , options ) {
if ( ! options ) {
options = { encoding : 'utf8' , mode : 0o666 , flag : 'w' } ;
} else if ( util . isString ( options ) ) {
} else if ( typeof options === 'string' ) {
options = { encoding : options , mode : 0o666 , flag : 'w' } ;
} else if ( ! util . isObject ( options ) ) {
} else if ( typeof options !== 'object' ) {
throw new TypeError ( 'Bad arguments' ) ;
}
@ -1079,7 +1079,7 @@ fs.writeFileSync = function(path, data, options) {
var flag = options . flag || 'w' ;
var fd = fs . openSync ( path , flag , options . mode ) ;
if ( ! util . isBuffer ( data ) ) {
if ( ! ( data instanceof Buffer ) ) {
data = new Buffer ( '' + data , options . encoding || 'utf8' ) ;
}
var written = 0 ;
@ -1098,11 +1098,11 @@ fs.writeFileSync = function(path, data, options) {
fs . appendFile = function ( path , data , options , callback_ ) {
var callback = maybeCallback ( arguments [ arguments . length - 1 ] ) ;
if ( util . isFunction ( options ) || ! options ) {
if ( ! options || typeof options === 'function' ) {
options = { encoding : 'utf8' , mode : 0o666 , flag : 'a' } ;
} else if ( util . isString ( options ) ) {
} else if ( typeof options === 'string' ) {
options = { encoding : options , mode : 0o666 , flag : 'a' } ;
} else if ( ! util . isObject ( options ) ) {
} else if ( typeof options !== 'object' ) {
throw new TypeError ( 'Bad arguments' ) ;
}
@ -1114,9 +1114,9 @@ fs.appendFile = function(path, data, options, callback_) {
fs . appendFileSync = function ( path , data , options ) {
if ( ! options ) {
options = { encoding : 'utf8' , mode : 0o666 , flag : 'a' } ;
} else if ( util . isString ( options ) ) {
} else if ( typeof options === 'string' ) {
options = { encoding : options , mode : 0o666 , flag : 'a' } ;
} else if ( ! util . isObject ( options ) ) {
} else if ( typeof options !== 'object' ) {
throw new TypeError ( 'Bad arguments' ) ;
}
if ( ! options . flag )
@ -1165,7 +1165,7 @@ fs.watch = function(filename) {
var options ;
var listener ;
if ( util . isObject ( arguments [ 1 ] ) ) {
if ( arguments [ 1 ] !== null && typeof arguments [ 1 ] === 'object' ) {
options = arguments [ 1 ] ;
listener = arguments [ 2 ] ;
} else {
@ -1173,8 +1173,8 @@ fs.watch = function(filename) {
listener = arguments [ 1 ] ;
}
if ( util . isUndefined ( options . persistent ) ) options . persistent = true ;
if ( util . isUndefined ( options . recursive ) ) options . recursive = false ;
if ( options . persistent === undefined ) options . persistent = true ;
if ( options . recursive === undefined ) options . recursive = false ;
watcher = new FSWatcher ( ) ;
watcher . start ( filename , options . persistent , options . recursive ) ;
@ -1247,7 +1247,7 @@ fs.watchFile = function(filename) {
persistent : true
} ;
if ( util . isObject ( arguments [ 1 ] ) ) {
if ( arguments [ 1 ] !== null && typeof arguments [ 1 ] === 'object' ) {
options = util . _ extend ( options , arguments [ 1 ] ) ;
listener = arguments [ 2 ] ;
} else {
@ -1275,7 +1275,7 @@ fs.unwatchFile = function(filename, listener) {
var stat = statWatchers [ filename ] ;
if ( util . isFunction ( listener ) ) {
if ( typeof listener === 'function' ) {
stat . removeListener ( 'change' , listener ) ;
} else {
stat . removeAllListeners ( 'change' ) ;
@ -1378,7 +1378,7 @@ fs.realpathSync = function realpathSync(p, cache) {
linkTarget = seenLinks [ id ] ;
}
}
if ( util . isNull ( linkTarget ) ) {
if ( linkTarget === null ) {
fs . statSync ( base ) ;
linkTarget = fs . readlinkSync ( base ) ;
}
@ -1400,7 +1400,7 @@ fs.realpathSync = function realpathSync(p, cache) {
fs . realpath = function realpath ( p , cache , cb ) {
if ( ! util . isFunction ( cb ) ) {
if ( typeof cb !== 'function' ) {
cb = maybeCallback ( cache ) ;
cache = null ;
}
@ -1561,13 +1561,13 @@ function ReadStream(path, options) {
options . autoClose : true ;
this . pos = undefined ;
if ( ! util . isUndefined ( this . start ) ) {
if ( ! util . isNumber ( this . start ) ) {
if ( this . start !== undefined ) {
if ( typeof this . start !== 'number' ) {
throw TypeError ( 'start must be a Number' ) ;
}
if ( util . isUndefined ( this . end ) ) {
if ( this . end === undefined ) {
this . end = Infinity ;
} else if ( ! util . isNumber ( this . end ) ) {
} else if ( typeof this . end !== 'number' ) {
throw TypeError ( 'end must be a Number' ) ;
}
@ -1578,7 +1578,7 @@ function ReadStream(path, options) {
this . pos = this . start ;
}
if ( ! util . isNumber ( this . fd ) )
if ( typeof this . fd !== 'number' )
this . open ( ) ;
this . on ( 'end' , function ( ) {
@ -1609,7 +1609,7 @@ ReadStream.prototype.open = function() {
} ;
ReadStream . prototype . _ read = function ( n ) {
if ( ! util . isNumber ( this . fd ) )
if ( typeof this . fd !== 'number' )
return this . once ( 'open' , function ( ) {
this . _ read ( n ) ;
} ) ;
@ -1630,7 +1630,7 @@ ReadStream.prototype._read = function(n) {
var toRead = Math . min ( pool . length - pool . used , n ) ;
var start = pool . used ;
if ( ! util . isUndefined ( this . pos ) )
if ( this . pos !== undefined )
toRead = Math . min ( this . end - this . pos + 1 , toRead ) ;
// already read everything we were supposed to read!
@ -1643,7 +1643,7 @@ ReadStream.prototype._read = function(n) {
fs . read ( this . fd , pool , pool . used , toRead , this . pos , onread ) ;
// move the pool positions, and internal position for reading.
if ( ! util . isUndefined ( this . pos ) )
if ( this . pos !== undefined )
this . pos += toRead ;
pool . used += toRead ;
@ -1676,8 +1676,8 @@ ReadStream.prototype.close = function(cb) {
var self = this ;
if ( cb )
this . once ( 'close' , cb ) ;
if ( this . closed || ! util . isNumber ( this . fd ) ) {
if ( ! util . isNumber ( this . fd ) ) {
if ( this . closed || typeof this . fd !== 'number' ) {
if ( typeof this . fd !== 'number' ) {
this . once ( 'open' , close ) ;
return ;
}
@ -1725,8 +1725,8 @@ function WriteStream(path, options) {
this . pos = undefined ;
this . bytesWritten = 0 ;
if ( ! util . isUndefined ( this . start ) ) {
if ( ! util . isNumber ( this . start ) ) {
if ( this . start !== undefined ) {
if ( typeof this . start !== 'number' ) {
throw TypeError ( 'start must be a Number' ) ;
}
if ( this . start < 0 ) {
@ -1736,7 +1736,7 @@ function WriteStream(path, options) {
this . pos = this . start ;
}
if ( ! util . isNumber ( this . fd ) )
if ( typeof this . fd !== 'number' )
this . open ( ) ;
// dispose on finish.
@ -1761,10 +1761,10 @@ WriteStream.prototype.open = function() {
WriteStream . prototype . _ write = function ( data , encoding , cb ) {
if ( ! util . isBuffer ( data ) )
if ( ! ( data instanceof Buffer ) )
return this . emit ( 'error' , new Error ( 'Invalid data' ) ) ;
if ( ! util . isNumber ( this . fd ) )
if ( typeof this . fd !== 'number' )
return this . once ( 'open' , function ( ) {
this . _ write ( data , encoding , cb ) ;
} ) ;
@ -1779,7 +1779,7 @@ WriteStream.prototype._write = function(data, encoding, cb) {
cb ( ) ;
} ) ;
if ( ! util . isUndefined ( this . pos ) )
if ( this . pos !== undefined )
this . pos += data . length ;
} ;
@ -1817,10 +1817,10 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) {
// parse arguments
if ( arg1 ) {
if ( util . isString ( arg1 ) ) {
if ( typeof arg1 === 'string' ) {
encoding = arg1 ;
cb = arg2 ;
} else if ( util . isFunction ( arg1 ) ) {
} else if ( typeof arg1 === 'function' ) {
cb = arg1 ;
} else {
throw new Error ( 'bad arg' ) ;
@ -1829,7 +1829,7 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) {
assertEncoding ( encoding ) ;
// Change strings to buffers. SLOW
if ( util . isString ( data ) ) {
if ( typeof data === 'string' ) {
data = new Buffer ( data , encoding ) ;
}