|
|
@ -3,6 +3,7 @@ var events = require('events'); |
|
|
|
var Buffer = require('buffer').Buffer; |
|
|
|
|
|
|
|
var binding = process.binding('fs'); |
|
|
|
var constants = process.binding('constants'); |
|
|
|
var fs = exports; |
|
|
|
|
|
|
|
var kMinPoolSpace = 128; |
|
|
@ -11,35 +12,35 @@ var kPoolSize = 40 * 1024; |
|
|
|
fs.Stats = binding.Stats; |
|
|
|
|
|
|
|
fs.Stats.prototype._checkModeProperty = function (property) { |
|
|
|
return ((this.mode & process.S_IFMT) === property); |
|
|
|
return ((this.mode & constants.S_IFMT) === property); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.Stats.prototype.isDirectory = function () { |
|
|
|
return this._checkModeProperty(process.S_IFDIR); |
|
|
|
return this._checkModeProperty(constants.S_IFDIR); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.Stats.prototype.isFile = function () { |
|
|
|
return this._checkModeProperty(process.S_IFREG); |
|
|
|
return this._checkModeProperty(constants.S_IFREG); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.Stats.prototype.isBlockDevice = function () { |
|
|
|
return this._checkModeProperty(process.S_IFBLK); |
|
|
|
return this._checkModeProperty(constants.S_IFBLK); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.Stats.prototype.isCharacterDevice = function () { |
|
|
|
return this._checkModeProperty(process.S_IFCHR); |
|
|
|
return this._checkModeProperty(constants.S_IFCHR); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.Stats.prototype.isSymbolicLink = function () { |
|
|
|
return this._checkModeProperty(process.S_IFLNK); |
|
|
|
return this._checkModeProperty(constants.S_IFLNK); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.Stats.prototype.isFIFO = function () { |
|
|
|
return this._checkModeProperty(process.S_IFIFO); |
|
|
|
return this._checkModeProperty(constants.S_IFIFO); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.Stats.prototype.isSocket = function () { |
|
|
|
return this._checkModeProperty(process.S_IFSOCK); |
|
|
|
return this._checkModeProperty(constants.S_IFSOCK); |
|
|
|
}; |
|
|
|
|
|
|
|
fs.readFile = function (path, encoding_, callback) { |
|
|
@ -48,7 +49,7 @@ fs.readFile = function (path, encoding_, callback) { |
|
|
|
var callback = (typeof(callback_) == 'function' ? callback_ : noop); |
|
|
|
binding.stat(path, function (err, stat) { |
|
|
|
if (err) { callback(err); return; } |
|
|
|
binding.open(path, process.O_RDONLY, 0666, function (err, fd) { |
|
|
|
binding.open(path, constants.O_RDONLY, 0666, function (err, fd) { |
|
|
|
if (err) { callback(err); return; } |
|
|
|
var size = stat.size; |
|
|
|
var buffer = new Buffer(size); |
|
|
@ -91,7 +92,7 @@ fs.readFile = function (path, encoding_, callback) { |
|
|
|
}; |
|
|
|
|
|
|
|
fs.readFileSync = function (path, encoding) { |
|
|
|
var fd = fs.openSync(path, process.O_RDONLY, 0666); |
|
|
|
var fd = fs.openSync(path, constants.O_RDONLY, 0666); |
|
|
|
var stat = fs.statSync(path); |
|
|
|
var buffer = new Buffer(stat.size); |
|
|
|
var nread = 0; |
|
|
@ -117,12 +118,12 @@ function stringToFlags(flag) { |
|
|
|
return flag; |
|
|
|
} |
|
|
|
switch (flag) { |
|
|
|
case "r": return process.O_RDONLY; |
|
|
|
case "r+": return process.O_RDWR; |
|
|
|
case "w": return process.O_CREAT | process.O_TRUNC | process.O_WRONLY; |
|
|
|
case "w+": return process.O_CREAT | process.O_TRUNC | process.O_RDWR; |
|
|
|
case "a": return process.O_APPEND | process.O_CREAT | process.O_WRONLY; |
|
|
|
case "a+": return process.O_APPEND | process.O_CREAT | process.O_RDWR; |
|
|
|
case "r": return constants.O_RDONLY; |
|
|
|
case "r+": return constants.O_RDWR; |
|
|
|
case "w": return constants.O_CREAT | constants.O_TRUNC | constants.O_WRONLY; |
|
|
|
case "w+": return constants.O_CREAT | constants.O_TRUNC | constants.O_RDWR; |
|
|
|
case "a": return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY; |
|
|
|
case "a+": return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR; |
|
|
|
default: throw new Error("Unknown file open flag: " + flag); |
|
|
|
} |
|
|
|
} |
|
|
|