Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Cleanup node.fs.cat to follow the newer style to match the code of fi…
Browse files Browse the repository at this point in the history
…le.writeFile
  • Loading branch information
Timothy Caswell authored and ry committed Oct 13, 2009
1 parent 2b8ab7e commit 8bf9a42
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,41 @@ node.fs.exists = function (path, callback) {
};

node.fs.cat = function (path, encoding) {
var open_promise = node.fs.open(path, node.O_RDONLY, 0666);
var cat_promise = new node.Promise();
var promise = new node.Promise();

encoding = encoding || "utf8"; // default to utf8

encoding = encoding || "utf8";

open_promise.addErrback(function () {
cat_promise.emitError(new Error("Could not open " + path));
});
open_promise.addCallback(function (fd) {
var content = "";
var pos = 0;
node.fs.open(path, node.O_RDONLY, 0666).addCallback(function (fd) {
var content = "", pos = 0;

function readChunk () {
var read_promise = node.fs.read(fd, 16*1024, pos, encoding);

read_promise.addErrback(function () { cat_promise.emitError(); });

read_promise.addCallback(function (chunk, bytes_read) {
node.fs.read(fd, 16*1024, pos, encoding).addCallback(function (chunk, bytes_read) {
if (chunk) {
if (chunk.constructor == String)
if (chunk.constructor === String) {
content += chunk;
else
} else {
content = content.concat(chunk);
}

pos += bytes_read;
readChunk();
} else {
cat_promise.emitSuccess(content);
promise.emitSuccess(content);
node.fs.close(fd);
}
}).addErrback(function () {
promise.emitError();
});
}
readChunk();
}).addErrback(function () {
promise.emitError(new Error("Could not open " + path));
});
return cat_promise;
return promise;
};

node.fs.Stats.prototype._checkModeProperty = function (property) {
return ((this.mode & property) == property);
return ((this.mode & property) === property);
};

node.fs.Stats.prototype.isDirectory = function () {
Expand Down

0 comments on commit 8bf9a42

Please sign in to comment.