1 node.fs.exists = function (path, callback) {
2 var p = node.fs.stat(path);
3 p.addCallback(function () { callback(true); });
4 p.addErrback(function () { callback(false); });
7 node.fs.cat = function (path, encoding) {
8 var promise = new node.Promise();
10 encoding = encoding || "utf8"; // default to utf8
12 node.fs.open(path, node.O_RDONLY, 0666).addCallback(function (fd) {
13 var content = "", pos = 0;
15 function readChunk () {
16 node.fs.read(fd, 16*1024, pos, encoding).addCallback(function (chunk, bytes_read) {
18 if (chunk.constructor === String) {
21 content = content.concat(chunk);
27 promise.emitSuccess(content);
30 }).addErrback(function () {
35 }).addErrback(function () {
36 promise.emitError(new Error("Could not open " + path));