Implemented posix.catSync()
This commit is contained in:
Родитель
1b42276851
Коммит
6c94b8e4e4
17
src/node.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;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
process.mixin(require('./common'));
|
||||
|
||||
var fixture = path.join(__dirname, "fixtures/x.txt");
|
||||
|
||||
assert.equal("xyz\n", posix.catSync(fixture));
|
Загрузка…
Ссылка в новой задаче