|
@ -5,45 +5,41 @@ node.fs.exists = function (path, callback) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.fs.cat = function (path, encoding) { |
|
|
node.fs.cat = function (path, encoding) { |
|
|
var open_promise = node.fs.open(path, node.O_RDONLY, 0666); |
|
|
var promise = new node.Promise(); |
|
|
var cat_promise = new node.Promise(); |
|
|
|
|
|
|
|
|
|
|
|
encoding = encoding || "utf8"; |
|
|
encoding = encoding || "utf8"; // default to utf8
|
|
|
|
|
|
|
|
|
open_promise.addErrback(function () { |
|
|
node.fs.open(path, node.O_RDONLY, 0666).addCallback(function (fd) { |
|
|
cat_promise.emitError(new Error("Could not open " + path)); |
|
|
var content = "", pos = 0; |
|
|
}); |
|
|
|
|
|
open_promise.addCallback(function (fd) { |
|
|
|
|
|
var content = ""; |
|
|
|
|
|
var pos = 0; |
|
|
|
|
|
|
|
|
|
|
|
function readChunk () { |
|
|
function readChunk () { |
|
|
var read_promise = node.fs.read(fd, 16*1024, pos, encoding); |
|
|
node.fs.read(fd, 16*1024, pos, encoding).addCallback(function (chunk, bytes_read) { |
|
|
|
|
|
|
|
|
read_promise.addErrback(function () { cat_promise.emitError(); }); |
|
|
|
|
|
|
|
|
|
|
|
read_promise.addCallback(function (chunk, bytes_read) { |
|
|
|
|
|
if (chunk) { |
|
|
if (chunk) { |
|
|
if (chunk.constructor == String) |
|
|
if (chunk.constructor === String) { |
|
|
content += chunk; |
|
|
content += chunk; |
|
|
else |
|
|
} else { |
|
|
content = content.concat(chunk); |
|
|
content = content.concat(chunk); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
pos += bytes_read; |
|
|
pos += bytes_read; |
|
|
readChunk(); |
|
|
readChunk(); |
|
|
} else { |
|
|
} else { |
|
|
cat_promise.emitSuccess(content); |
|
|
promise.emitSuccess(content); |
|
|
node.fs.close(fd); |
|
|
node.fs.close(fd); |
|
|
} |
|
|
} |
|
|
|
|
|
}).addErrback(function () { |
|
|
|
|
|
promise.emitError(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
readChunk(); |
|
|
readChunk(); |
|
|
|
|
|
}).addErrback(function () { |
|
|
|
|
|
promise.emitError(new Error("Could not open " + path)); |
|
|
}); |
|
|
}); |
|
|
return cat_promise; |
|
|
return promise; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.fs.Stats.prototype._checkModeProperty = function (property) { |
|
|
node.fs.Stats.prototype._checkModeProperty = function (property) { |
|
|
return ((this.mode & property) == property); |
|
|
return ((this.mode & property) === property); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
node.fs.Stats.prototype.isDirectory = function () { |
|
|
node.fs.Stats.prototype.isDirectory = function () { |
|
|