|
@ -81,14 +81,14 @@ function rethrow() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function maybeCallback(cb) { |
|
|
function maybeCallback(cb) { |
|
|
return IS_FUNCTION(cb) ? cb : rethrow(); |
|
|
return util.isFunction(cb) ? cb : rethrow(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Ensure that callbacks run in the global context. Only use this function
|
|
|
// Ensure that callbacks run in the global context. Only use this function
|
|
|
// for callbacks that are passed to the binding layer, callbacks that are
|
|
|
// for callbacks that are passed to the binding layer, callbacks that are
|
|
|
// invoked from JS already run in the proper scope.
|
|
|
// invoked from JS already run in the proper scope.
|
|
|
function makeCallback(cb) { |
|
|
function makeCallback(cb) { |
|
|
if (!IS_FUNCTION(cb)) { |
|
|
if (!util.isFunction(cb)) { |
|
|
return rethrow(); |
|
|
return rethrow(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -171,13 +171,13 @@ fs.existsSync = function(path) { |
|
|
fs.readFile = function(path, options, callback_) { |
|
|
fs.readFile = function(path, options, callback_) { |
|
|
var callback = maybeCallback(arguments[arguments.length - 1]); |
|
|
var callback = maybeCallback(arguments[arguments.length - 1]); |
|
|
|
|
|
|
|
|
if (IS_FUNCTION(options) || !options) { |
|
|
if (util.isFunction(options) || !options) { |
|
|
options = { encoding: null, flag: 'r' }; |
|
|
options = { encoding: null, flag: 'r' }; |
|
|
} else if (IS_STRING(options)) { |
|
|
} else if (util.isString(options)) { |
|
|
options = { encoding: options, flag: 'r' }; |
|
|
options = { encoding: options, flag: 'r' }; |
|
|
} else if (!options) { |
|
|
} else if (!options) { |
|
|
options = { encoding: null, flag: 'r' }; |
|
|
options = { encoding: null, flag: 'r' }; |
|
|
} else if (!IS_OBJECT(options)) { |
|
|
} else if (!util.isObject(options)) { |
|
|
throw new TypeError('Bad arguments'); |
|
|
throw new TypeError('Bad arguments'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -260,9 +260,9 @@ fs.readFile = function(path, options, callback_) { |
|
|
fs.readFileSync = function(path, options) { |
|
|
fs.readFileSync = function(path, options) { |
|
|
if (!options) { |
|
|
if (!options) { |
|
|
options = { encoding: null, flag: 'r' }; |
|
|
options = { encoding: null, flag: 'r' }; |
|
|
} else if (IS_STRING(options)) { |
|
|
} else if (util.isString(options)) { |
|
|
options = { encoding: options, flag: 'r' }; |
|
|
options = { encoding: options, flag: 'r' }; |
|
|
} else if (!IS_OBJECT(options)) { |
|
|
} else if (!util.isObject(options)) { |
|
|
throw new TypeError('Bad arguments'); |
|
|
throw new TypeError('Bad arguments'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -332,7 +332,7 @@ fs.readFileSync = function(path, options) { |
|
|
// Used by binding.open and friends
|
|
|
// Used by binding.open and friends
|
|
|
function stringToFlags(flag) { |
|
|
function stringToFlags(flag) { |
|
|
// Only mess with strings
|
|
|
// Only mess with strings
|
|
|
if (!IS_STRING(flag)) { |
|
|
if (!util.isString(flag)) { |
|
|
return flag; |
|
|
return flag; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -381,9 +381,9 @@ fs.closeSync = function(fd) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
function modeNum(m, def) { |
|
|
function modeNum(m, def) { |
|
|
if (IS_NUMBER(m)) |
|
|
if (util.isNumber(m)) |
|
|
return m; |
|
|
return m; |
|
|
if (IS_STRING(m)) |
|
|
if (util.isString(m)) |
|
|
return parseInt(m, 8); |
|
|
return parseInt(m, 8); |
|
|
if (def) |
|
|
if (def) |
|
|
return modeNum(def); |
|
|
return modeNum(def); |
|
@ -408,7 +408,7 @@ fs.openSync = function(path, flags, mode) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
fs.read = function(fd, buffer, offset, length, position, callback) { |
|
|
fs.read = function(fd, buffer, offset, length, position, callback) { |
|
|
if (!IS_BUFFER(buffer)) { |
|
|
if (!util.isBuffer(buffer)) { |
|
|
// legacy string interface (fd, length, position, encoding, callback)
|
|
|
// legacy string interface (fd, length, position, encoding, callback)
|
|
|
var cb = arguments[4], |
|
|
var cb = arguments[4], |
|
|
encoding = arguments[3]; |
|
|
encoding = arguments[3]; |
|
@ -439,7 +439,7 @@ fs.read = function(fd, buffer, offset, length, position, callback) { |
|
|
|
|
|
|
|
|
fs.readSync = function(fd, buffer, offset, length, position) { |
|
|
fs.readSync = function(fd, buffer, offset, length, position) { |
|
|
var legacy = false; |
|
|
var legacy = false; |
|
|
if (!IS_BUFFER(buffer)) { |
|
|
if (!util.isBuffer(buffer)) { |
|
|
// legacy string interface (fd, length, position, encoding, callback)
|
|
|
// legacy string interface (fd, length, position, encoding, callback)
|
|
|
legacy = true; |
|
|
legacy = true; |
|
|
var encoding = arguments[3]; |
|
|
var encoding = arguments[3]; |
|
@ -467,9 +467,9 @@ fs.readSync = function(fd, buffer, offset, length, position) { |
|
|
// OR
|
|
|
// OR
|
|
|
// fs.write(fd, string[, position[, encoding]], callback);
|
|
|
// fs.write(fd, string[, position[, encoding]], callback);
|
|
|
fs.write = function(fd, buffer, offset, length, position, callback) { |
|
|
fs.write = function(fd, buffer, offset, length, position, callback) { |
|
|
if (IS_BUFFER(buffer)) { |
|
|
if (util.isBuffer(buffer)) { |
|
|
// if no position is passed then assume null
|
|
|
// if no position is passed then assume null
|
|
|
if (IS_FUNCTION(position)) { |
|
|
if (util.isFunction(position)) { |
|
|
callback = position; |
|
|
callback = position; |
|
|
position = null; |
|
|
position = null; |
|
|
} |
|
|
} |
|
@ -481,10 +481,10 @@ fs.write = function(fd, buffer, offset, length, position, callback) { |
|
|
return binding.writeBuffer(fd, buffer, offset, length, position, wrapper); |
|
|
return binding.writeBuffer(fd, buffer, offset, length, position, wrapper); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (IS_STRING(buffer)) |
|
|
if (util.isString(buffer)) |
|
|
buffer += ''; |
|
|
buffer += ''; |
|
|
if (!IS_FUNCTION(position)) { |
|
|
if (!util.isFunction(position)) { |
|
|
if (IS_FUNCTION(offset)) { |
|
|
if (util.isFunction(offset)) { |
|
|
position = offset; |
|
|
position = offset; |
|
|
offset = null; |
|
|
offset = null; |
|
|
} else { |
|
|
} else { |
|
@ -505,14 +505,14 @@ fs.write = function(fd, buffer, offset, length, position, callback) { |
|
|
// OR
|
|
|
// OR
|
|
|
// fs.writeSync(fd, string[, position[, encoding]]);
|
|
|
// fs.writeSync(fd, string[, position[, encoding]]);
|
|
|
fs.writeSync = function(fd, buffer, offset, length, position) { |
|
|
fs.writeSync = function(fd, buffer, offset, length, position) { |
|
|
if (IS_BUFFER(buffer)) { |
|
|
if (util.isBuffer(buffer)) { |
|
|
if (IS_UNDEFINED(position)) |
|
|
if (util.isUndefined(position)) |
|
|
position = null; |
|
|
position = null; |
|
|
return binding.writeBuffer(fd, buffer, offset, length, position); |
|
|
return binding.writeBuffer(fd, buffer, offset, length, position); |
|
|
} |
|
|
} |
|
|
if (!IS_STRING(buffer)) |
|
|
if (!util.isString(buffer)) |
|
|
buffer += ''; |
|
|
buffer += ''; |
|
|
if (IS_UNDEFINED(offset)) |
|
|
if (util.isUndefined(offset)) |
|
|
offset = null; |
|
|
offset = null; |
|
|
return binding.writeString(fd, buffer, offset, length, position); |
|
|
return binding.writeString(fd, buffer, offset, length, position); |
|
|
}; |
|
|
}; |
|
@ -534,14 +534,14 @@ fs.renameSync = function(oldPath, newPath) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
fs.truncate = function(path, len, callback) { |
|
|
fs.truncate = function(path, len, callback) { |
|
|
if (IS_NUMBER(path)) { |
|
|
if (util.isNumber(path)) { |
|
|
// legacy
|
|
|
// legacy
|
|
|
return fs.ftruncate(path, len, callback); |
|
|
return fs.ftruncate(path, len, callback); |
|
|
} |
|
|
} |
|
|
if (IS_FUNCTION(len)) { |
|
|
if (util.isFunction(len)) { |
|
|
callback = len; |
|
|
callback = len; |
|
|
len = 0; |
|
|
len = 0; |
|
|
} else if (IS_UNDEFINED(len)) { |
|
|
} else if (util.isUndefined(len)) { |
|
|
len = 0; |
|
|
len = 0; |
|
|
} |
|
|
} |
|
|
callback = maybeCallback(callback); |
|
|
callback = maybeCallback(callback); |
|
@ -556,11 +556,11 @@ fs.truncate = function(path, len, callback) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
fs.truncateSync = function(path, len) { |
|
|
fs.truncateSync = function(path, len) { |
|
|
if (IS_NUMBER(path)) { |
|
|
if (util.isNumber(path)) { |
|
|
// legacy
|
|
|
// legacy
|
|
|
return fs.ftruncateSync(path, len); |
|
|
return fs.ftruncateSync(path, len); |
|
|
} |
|
|
} |
|
|
if (IS_UNDEFINED(len)) { |
|
|
if (util.isUndefined(len)) { |
|
|
len = 0; |
|
|
len = 0; |
|
|
} |
|
|
} |
|
|
// allow error to be thrown, but still close fd.
|
|
|
// allow error to be thrown, but still close fd.
|
|
@ -574,17 +574,17 @@ fs.truncateSync = function(path, len) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
fs.ftruncate = function(fd, len, callback) { |
|
|
fs.ftruncate = function(fd, len, callback) { |
|
|
if (IS_FUNCTION(len)) { |
|
|
if (util.isFunction(len)) { |
|
|
callback = len; |
|
|
callback = len; |
|
|
len = 0; |
|
|
len = 0; |
|
|
} else if (IS_UNDEFINED(len)) { |
|
|
} else if (util.isUndefined(len)) { |
|
|
len = 0; |
|
|
len = 0; |
|
|
} |
|
|
} |
|
|
binding.ftruncate(fd, len, makeCallback(callback)); |
|
|
binding.ftruncate(fd, len, makeCallback(callback)); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
fs.ftruncateSync = function(fd, len) { |
|
|
fs.ftruncateSync = function(fd, len) { |
|
|
if (IS_UNDEFINED(len)) { |
|
|
if (util.isUndefined(len)) { |
|
|
len = 0; |
|
|
len = 0; |
|
|
} |
|
|
} |
|
|
return binding.ftruncate(fd, len); |
|
|
return binding.ftruncate(fd, len); |
|
@ -618,7 +618,7 @@ fs.fsyncSync = function(fd) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
fs.mkdir = function(path, mode, callback) { |
|
|
fs.mkdir = function(path, mode, callback) { |
|
|
if (IS_FUNCTION(mode)) callback = mode; |
|
|
if (util.isFunction(mode)) callback = mode; |
|
|
callback = makeCallback(callback); |
|
|
callback = makeCallback(callback); |
|
|
if (!nullCheck(path, callback)) return; |
|
|
if (!nullCheck(path, callback)) return; |
|
|
binding.mkdir(pathModule._makeLong(path), |
|
|
binding.mkdir(pathModule._makeLong(path), |
|
@ -698,7 +698,7 @@ function preprocessSymlinkDestination(path, type) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fs.symlink = function(destination, path, type_, callback) { |
|
|
fs.symlink = function(destination, path, type_, callback) { |
|
|
var type = (IS_STRING(type_) ? type_ : null); |
|
|
var type = (util.isString(type_) ? type_ : null); |
|
|
var callback = makeCallback(arguments[arguments.length - 1]); |
|
|
var callback = makeCallback(arguments[arguments.length - 1]); |
|
|
|
|
|
|
|
|
if (!nullCheck(destination, callback)) return; |
|
|
if (!nullCheck(destination, callback)) return; |
|
@ -711,7 +711,7 @@ fs.symlink = function(destination, path, type_, callback) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
fs.symlinkSync = function(destination, path, type) { |
|
|
fs.symlinkSync = function(destination, path, type) { |
|
|
type = (IS_STRING(type) ? type : null); |
|
|
type = (util.isString(type) ? type : null); |
|
|
|
|
|
|
|
|
nullCheck(destination); |
|
|
nullCheck(destination); |
|
|
nullCheck(path); |
|
|
nullCheck(path); |
|
@ -849,10 +849,10 @@ fs.chownSync = function(path, uid, gid) { |
|
|
|
|
|
|
|
|
// converts Date or number to a fractional UNIX timestamp
|
|
|
// converts Date or number to a fractional UNIX timestamp
|
|
|
function toUnixTimestamp(time) { |
|
|
function toUnixTimestamp(time) { |
|
|
if (IS_NUMBER(time)) { |
|
|
if (util.isNumber(time)) { |
|
|
return time; |
|
|
return time; |
|
|
} |
|
|
} |
|
|
if (IS_DATE(time)) { |
|
|
if (util.isDate(time)) { |
|
|
// convert to 123.456 UNIX timestamp
|
|
|
// convert to 123.456 UNIX timestamp
|
|
|
return time.getTime() / 1000; |
|
|
return time.getTime() / 1000; |
|
|
} |
|
|
} |
|
@ -915,13 +915,13 @@ function writeAll(fd, buffer, offset, length, position, callback) { |
|
|
fs.writeFile = function(path, data, options, callback) { |
|
|
fs.writeFile = function(path, data, options, callback) { |
|
|
var callback = maybeCallback(arguments[arguments.length - 1]); |
|
|
var callback = maybeCallback(arguments[arguments.length - 1]); |
|
|
|
|
|
|
|
|
if (IS_FUNCTION(options) || !options) { |
|
|
if (util.isFunction(options) || !options) { |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' }; |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' }; |
|
|
} else if (IS_STRING(options)) { |
|
|
} else if (util.isString(options)) { |
|
|
options = { encoding: options, mode: 438, flag: 'w' }; |
|
|
options = { encoding: options, mode: 438, flag: 'w' }; |
|
|
} else if (!options) { |
|
|
} else if (!options) { |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' }; |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' }; |
|
|
} else if (!IS_OBJECT(options)) { |
|
|
} else if (!util.isObject(options)) { |
|
|
throw new TypeError('Bad arguments'); |
|
|
throw new TypeError('Bad arguments'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -932,7 +932,7 @@ fs.writeFile = function(path, data, options, callback) { |
|
|
if (openErr) { |
|
|
if (openErr) { |
|
|
if (callback) callback(openErr); |
|
|
if (callback) callback(openErr); |
|
|
} else { |
|
|
} else { |
|
|
var buffer = IS_BUFFER(data) ? data : new Buffer('' + data, |
|
|
var buffer = util.isBuffer(data) ? data : new Buffer('' + data, |
|
|
options.encoding || 'utf8'); |
|
|
options.encoding || 'utf8'); |
|
|
var position = /a/.test(flag) ? null : 0; |
|
|
var position = /a/.test(flag) ? null : 0; |
|
|
writeAll(fd, buffer, 0, buffer.length, position, callback); |
|
|
writeAll(fd, buffer, 0, buffer.length, position, callback); |
|
@ -943,9 +943,9 @@ fs.writeFile = function(path, data, options, callback) { |
|
|
fs.writeFileSync = function(path, data, options) { |
|
|
fs.writeFileSync = function(path, data, options) { |
|
|
if (!options) { |
|
|
if (!options) { |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' }; |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'w' }; |
|
|
} else if (IS_STRING(options)) { |
|
|
} else if (util.isString(options)) { |
|
|
options = { encoding: options, mode: 438, flag: 'w' }; |
|
|
options = { encoding: options, mode: 438, flag: 'w' }; |
|
|
} else if (!IS_OBJECT(options)) { |
|
|
} else if (!util.isObject(options)) { |
|
|
throw new TypeError('Bad arguments'); |
|
|
throw new TypeError('Bad arguments'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -953,7 +953,7 @@ fs.writeFileSync = function(path, data, options) { |
|
|
|
|
|
|
|
|
var flag = options.flag || 'w'; |
|
|
var flag = options.flag || 'w'; |
|
|
var fd = fs.openSync(path, flag, options.mode); |
|
|
var fd = fs.openSync(path, flag, options.mode); |
|
|
if (!IS_BUFFER(data)) { |
|
|
if (!util.isBuffer(data)) { |
|
|
data = new Buffer('' + data, options.encoding || 'utf8'); |
|
|
data = new Buffer('' + data, options.encoding || 'utf8'); |
|
|
} |
|
|
} |
|
|
var written = 0; |
|
|
var written = 0; |
|
@ -972,13 +972,13 @@ fs.writeFileSync = function(path, data, options) { |
|
|
fs.appendFile = function(path, data, options, callback_) { |
|
|
fs.appendFile = function(path, data, options, callback_) { |
|
|
var callback = maybeCallback(arguments[arguments.length - 1]); |
|
|
var callback = maybeCallback(arguments[arguments.length - 1]); |
|
|
|
|
|
|
|
|
if (IS_FUNCTION(options) || !options) { |
|
|
if (util.isFunction(options) || !options) { |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' }; |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' }; |
|
|
} else if (IS_STRING(options)) { |
|
|
} else if (util.isString(options)) { |
|
|
options = { encoding: options, mode: 438, flag: 'a' }; |
|
|
options = { encoding: options, mode: 438, flag: 'a' }; |
|
|
} else if (!options) { |
|
|
} else if (!options) { |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' }; |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' }; |
|
|
} else if (!IS_OBJECT(options)) { |
|
|
} else if (!util.isObject(options)) { |
|
|
throw new TypeError('Bad arguments'); |
|
|
throw new TypeError('Bad arguments'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -990,9 +990,9 @@ fs.appendFile = function(path, data, options, callback_) { |
|
|
fs.appendFileSync = function(path, data, options) { |
|
|
fs.appendFileSync = function(path, data, options) { |
|
|
if (!options) { |
|
|
if (!options) { |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' }; |
|
|
options = { encoding: 'utf8', mode: 438 /*=0666*/, flag: 'a' }; |
|
|
} else if (IS_STRING(options)) { |
|
|
} else if (util.isString(options)) { |
|
|
options = { encoding: options, mode: 438, flag: 'a' }; |
|
|
options = { encoding: options, mode: 438, flag: 'a' }; |
|
|
} else if (!IS_OBJECT(options)) { |
|
|
} else if (!util.isObject(options)) { |
|
|
throw new TypeError('Bad arguments'); |
|
|
throw new TypeError('Bad arguments'); |
|
|
} |
|
|
} |
|
|
if (!options.flag) |
|
|
if (!options.flag) |
|
@ -1039,7 +1039,7 @@ fs.watch = function(filename) { |
|
|
var options; |
|
|
var options; |
|
|
var listener; |
|
|
var listener; |
|
|
|
|
|
|
|
|
if (IS_OBJECT(arguments[1])) { |
|
|
if (util.isObject(arguments[1])) { |
|
|
options = arguments[1]; |
|
|
options = arguments[1]; |
|
|
listener = arguments[2]; |
|
|
listener = arguments[2]; |
|
|
} else { |
|
|
} else { |
|
@ -1047,7 +1047,7 @@ fs.watch = function(filename) { |
|
|
listener = arguments[1]; |
|
|
listener = arguments[1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (IS_UNDEFINED(options.persistent)) options.persistent = true; |
|
|
if (util.isUndefined(options.persistent)) options.persistent = true; |
|
|
|
|
|
|
|
|
watcher = new FSWatcher(); |
|
|
watcher = new FSWatcher(); |
|
|
watcher.start(filename, options.persistent); |
|
|
watcher.start(filename, options.persistent); |
|
@ -1119,7 +1119,7 @@ fs.watchFile = function(filename) { |
|
|
persistent: true |
|
|
persistent: true |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (IS_OBJECT(arguments[1])) { |
|
|
if (util.isObject(arguments[1])) { |
|
|
options = util._extend(options, arguments[1]); |
|
|
options = util._extend(options, arguments[1]); |
|
|
listener = arguments[2]; |
|
|
listener = arguments[2]; |
|
|
} else { |
|
|
} else { |
|
@ -1146,7 +1146,7 @@ fs.unwatchFile = function(filename, listener) { |
|
|
|
|
|
|
|
|
var stat = statWatchers[filename]; |
|
|
var stat = statWatchers[filename]; |
|
|
|
|
|
|
|
|
if (IS_FUNCTION(listener)) { |
|
|
if (util.isFunction(listener)) { |
|
|
stat.removeListener('change', listener); |
|
|
stat.removeListener('change', listener); |
|
|
} else { |
|
|
} else { |
|
|
stat.removeAllListeners('change'); |
|
|
stat.removeAllListeners('change'); |
|
@ -1255,7 +1255,7 @@ fs.realpathSync = function realpathSync(p, cache) { |
|
|
linkTarget = seenLinks[id]; |
|
|
linkTarget = seenLinks[id]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (IS_NULL(linkTarget)) { |
|
|
if (util.isNull(linkTarget)) { |
|
|
fs.statSync(base); |
|
|
fs.statSync(base); |
|
|
linkTarget = fs.readlinkSync(base); |
|
|
linkTarget = fs.readlinkSync(base); |
|
|
} |
|
|
} |
|
@ -1277,7 +1277,7 @@ fs.realpathSync = function realpathSync(p, cache) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fs.realpath = function realpath(p, cache, cb) { |
|
|
fs.realpath = function realpath(p, cache, cb) { |
|
|
if (!IS_FUNCTION(cb)) { |
|
|
if (!util.isFunction(cb)) { |
|
|
cb = maybeCallback(cache); |
|
|
cb = maybeCallback(cache); |
|
|
cache = null; |
|
|
cache = null; |
|
|
} |
|
|
} |
|
@ -1438,13 +1438,13 @@ function ReadStream(path, options) { |
|
|
options.autoClose : true; |
|
|
options.autoClose : true; |
|
|
this.pos = undefined; |
|
|
this.pos = undefined; |
|
|
|
|
|
|
|
|
if (!IS_UNDEFINED(this.start)) { |
|
|
if (!util.isUndefined(this.start)) { |
|
|
if (!IS_NUMBER(this.start)) { |
|
|
if (!util.isNumber(this.start)) { |
|
|
throw TypeError('start must be a Number'); |
|
|
throw TypeError('start must be a Number'); |
|
|
} |
|
|
} |
|
|
if (IS_UNDEFINED(this.end)) { |
|
|
if (util.isUndefined(this.end)) { |
|
|
this.end = Infinity; |
|
|
this.end = Infinity; |
|
|
} else if (!IS_NUMBER(this.end)) { |
|
|
} else if (!util.isNumber(this.end)) { |
|
|
throw TypeError('end must be a Number'); |
|
|
throw TypeError('end must be a Number'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1455,7 +1455,7 @@ function ReadStream(path, options) { |
|
|
this.pos = this.start; |
|
|
this.pos = this.start; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!IS_NUMBER(this.fd)) |
|
|
if (!util.isNumber(this.fd)) |
|
|
this.open(); |
|
|
this.open(); |
|
|
|
|
|
|
|
|
this.on('end', function() { |
|
|
this.on('end', function() { |
|
@ -1486,7 +1486,7 @@ ReadStream.prototype.open = function() { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
ReadStream.prototype._read = function(n) { |
|
|
ReadStream.prototype._read = function(n) { |
|
|
if (!IS_NUMBER(this.fd)) |
|
|
if (!util.isNumber(this.fd)) |
|
|
return this.once('open', function() { |
|
|
return this.once('open', function() { |
|
|
this._read(n); |
|
|
this._read(n); |
|
|
}); |
|
|
}); |
|
@ -1507,7 +1507,7 @@ ReadStream.prototype._read = function(n) { |
|
|
var toRead = Math.min(pool.length - pool.used, n); |
|
|
var toRead = Math.min(pool.length - pool.used, n); |
|
|
var start = pool.used; |
|
|
var start = pool.used; |
|
|
|
|
|
|
|
|
if (!IS_UNDEFINED(this.pos)) |
|
|
if (!util.isUndefined(this.pos)) |
|
|
toRead = Math.min(this.end - this.pos + 1, toRead); |
|
|
toRead = Math.min(this.end - this.pos + 1, toRead); |
|
|
|
|
|
|
|
|
// already read everything we were supposed to read!
|
|
|
// already read everything we were supposed to read!
|
|
@ -1520,7 +1520,7 @@ ReadStream.prototype._read = function(n) { |
|
|
fs.read(this.fd, pool, pool.used, toRead, this.pos, onread); |
|
|
fs.read(this.fd, pool, pool.used, toRead, this.pos, onread); |
|
|
|
|
|
|
|
|
// move the pool positions, and internal position for reading.
|
|
|
// move the pool positions, and internal position for reading.
|
|
|
if (!IS_UNDEFINED(this.pos)) |
|
|
if (!util.isUndefined(this.pos)) |
|
|
this.pos += toRead; |
|
|
this.pos += toRead; |
|
|
pool.used += toRead; |
|
|
pool.used += toRead; |
|
|
|
|
|
|
|
@ -1546,7 +1546,7 @@ ReadStream.prototype.destroy = function() { |
|
|
return; |
|
|
return; |
|
|
this.destroyed = true; |
|
|
this.destroyed = true; |
|
|
|
|
|
|
|
|
if (IS_NUMBER(this.fd)) |
|
|
if (util.isNumber(this.fd)) |
|
|
this.close(); |
|
|
this.close(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -1555,8 +1555,8 @@ ReadStream.prototype.close = function(cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
if (cb) |
|
|
if (cb) |
|
|
this.once('close', cb); |
|
|
this.once('close', cb); |
|
|
if (this.closed || !IS_NUMBER(this.fd)) { |
|
|
if (this.closed || !util.isNumber(this.fd)) { |
|
|
if (!IS_NUMBER(this.fd)) { |
|
|
if (!util.isNumber(this.fd)) { |
|
|
this.once('open', close); |
|
|
this.once('open', close); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -1604,8 +1604,8 @@ function WriteStream(path, options) { |
|
|
this.pos = undefined; |
|
|
this.pos = undefined; |
|
|
this.bytesWritten = 0; |
|
|
this.bytesWritten = 0; |
|
|
|
|
|
|
|
|
if (!IS_UNDEFINED(this.start)) { |
|
|
if (!util.isUndefined(this.start)) { |
|
|
if (!IS_NUMBER(this.start)) { |
|
|
if (!util.isNumber(this.start)) { |
|
|
throw TypeError('start must be a Number'); |
|
|
throw TypeError('start must be a Number'); |
|
|
} |
|
|
} |
|
|
if (this.start < 0) { |
|
|
if (this.start < 0) { |
|
@ -1615,7 +1615,7 @@ function WriteStream(path, options) { |
|
|
this.pos = this.start; |
|
|
this.pos = this.start; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!IS_NUMBER(this.fd)) |
|
|
if (!util.isNumber(this.fd)) |
|
|
this.open(); |
|
|
this.open(); |
|
|
|
|
|
|
|
|
// dispose on finish.
|
|
|
// dispose on finish.
|
|
@ -1640,10 +1640,10 @@ WriteStream.prototype.open = function() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteStream.prototype._write = function(data, encoding, cb) { |
|
|
WriteStream.prototype._write = function(data, encoding, cb) { |
|
|
if (!IS_BUFFER(data)) |
|
|
if (!util.isBuffer(data)) |
|
|
return this.emit('error', new Error('Invalid data')); |
|
|
return this.emit('error', new Error('Invalid data')); |
|
|
|
|
|
|
|
|
if (!IS_NUMBER(this.fd)) |
|
|
if (!util.isNumber(this.fd)) |
|
|
return this.once('open', function() { |
|
|
return this.once('open', function() { |
|
|
this._write(data, encoding, cb); |
|
|
this._write(data, encoding, cb); |
|
|
}); |
|
|
}); |
|
@ -1658,7 +1658,7 @@ WriteStream.prototype._write = function(data, encoding, cb) { |
|
|
cb(); |
|
|
cb(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (!IS_UNDEFINED(this.pos)) |
|
|
if (!util.isUndefined(this.pos)) |
|
|
this.pos += data.length; |
|
|
this.pos += data.length; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -1692,10 +1692,10 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) { |
|
|
|
|
|
|
|
|
// parse arguments
|
|
|
// parse arguments
|
|
|
if (arg1) { |
|
|
if (arg1) { |
|
|
if (IS_STRING(arg1)) { |
|
|
if (util.isString(arg1)) { |
|
|
encoding = arg1; |
|
|
encoding = arg1; |
|
|
cb = arg2; |
|
|
cb = arg2; |
|
|
} else if (IS_FUNCTION(arg1)) { |
|
|
} else if (util.isFunction(arg1)) { |
|
|
cb = arg1; |
|
|
cb = arg1; |
|
|
} else { |
|
|
} else { |
|
|
throw new Error('bad arg'); |
|
|
throw new Error('bad arg'); |
|
@ -1704,7 +1704,7 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) { |
|
|
assertEncoding(encoding); |
|
|
assertEncoding(encoding); |
|
|
|
|
|
|
|
|
// Change strings to buffers. SLOW
|
|
|
// Change strings to buffers. SLOW
|
|
|
if (IS_STRING(data)) { |
|
|
if (util.isString(data)) { |
|
|
data = new Buffer(data, encoding); |
|
|
data = new Buffer(data, encoding); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|