Implemented posix.catSync()

This commit is contained in:
Felix Geisendörfer authored and Ryan Dahl committed 2010-02-11 21:11:16 -08:00
1 parent 1b42276851
commit 6c94b8e4e4
2 files changed
+22

No files matched your search

+17
View File
@@ -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;
+5
View File
@@ -0,0 +1,5 @@
process.mixin(require('./common'));
var fixture = path.join(__dirname, "fixtures/x.txt");
assert.equal("xyz\n", posix.catSync(fixture));