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

Commit

Permalink
Implemented posix.catSync()
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge authored and ry committed Feb 12, 2010
1 parent 1b42276 commit 6c94b8e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/node.js
Expand Up @@ -675,6 +675,23 @@ var posixModule = createInternalModule("posix", function (exports) {
});
return promise;
};

exports.catSync = function (path, encoding) {
encoding = encoding || "utf8"; // default to utf8

var
fd = exports.openSync(path, process.O_RDONLY, 0666),
content = '',
pos = 0,
r;

while ((r = exports.readSync(fd, 16*1024, pos, encoding)) && r[0]) {
content += r[0];
pos += r[1]
}

return content;
};
});

var posix = posixModule.exports;
Expand Down
5 changes: 5 additions & 0 deletions test/mjsunit/test-sync-cat.js
@@ -0,0 +1,5 @@
process.mixin(require('./common'));

var fixture = path.join(__dirname, "fixtures/x.txt");

assert.equal("xyz\n", posix.catSync(fixture));

0 comments on commit 6c94b8e

Please sign in to comment.