fs: add sync open flags 'rs' and 'rs+'

This commit is contained in:
Kevin Bowman 2012-05-16 00:10:25 +02:00 committed by Ben Noordhuis
parent 643f00d3f9
commit dfcdd5b8aa
3 changed files with 18 additions and 1 deletions

View File

@ -270,6 +270,13 @@ An exception occurs if the file does not exist.
* `'r+'` - Open file for reading and writing.
An exception occurs if the file does not exist.
* `'rs'` - Open file for reading, telling the OS to open it synchronously
(ie using the O_SYNC flag). Whilst rarely useful, when used with caution by
those who know what they're doing it can be sometimes necessary. Note that
this doesn't turn `fs.open()` into a synchronous blocking call, if that's what
you want then you should be using `fs.openSync()`
An exception occurs if the file does not exist.
* `'w'` - Open file for writing.
The file is created (if it does not exist) or truncated (if it exists).

View File

@ -210,7 +210,9 @@ function stringToFlags(flag) {
switch (flag) {
case 'r' : return O_RDONLY;
case 'rs' : return O_RDONLY | O_SYNC;
case 'r+' : return O_RDWR;
case 'rs+' : return O_RDWR | O_SYNC;
case 'w' : return O_TRUNC | O_CREAT | O_WRONLY;
case 'wx' : // fall through

View File

@ -41,11 +41,19 @@ fs.open(__filename, 'r', function(err, fd) {
if (err) {
throw err;
}
openFd = fd;
});
var openFd2;
fs.open(__filename, 'rs', function(err, fd) {
if (err) {
throw err;
}
openFd2 = fd;
});
process.on('exit', function() {
assert.ok(openFd);
assert.ok(openFd2);
});