diff --git a/src/node.js b/src/node.js index 2ac9db46e6..7f16c8201d 100644 --- a/src/node.js +++ b/src/node.js @@ -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; diff --git a/test/mjsunit/test-sync-cat.js b/test/mjsunit/test-sync-cat.js new file mode 100644 index 0000000000..6e2ff30942 --- /dev/null +++ b/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)); \ No newline at end of file