Browse Source

Implemented posix.catSync()

v0.7.4-release
Felix Geisendörfer 15 years ago
committed by Ryan Dahl
parent
commit
6c94b8e4e4
  1. 17
      src/node.js
  2. 5
      test/mjsunit/test-sync-cat.js

17
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;

5
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));
Loading…
Cancel
Save