diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index 8e75a4c44f..178187a282 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -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). diff --git a/lib/fs.js b/lib/fs.js index ce9a471556..910a714d67 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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 diff --git a/test/simple/test-fs-open.js b/test/simple/test-fs-open.js index a0f225e03d..e334de9895 100644 --- a/test/simple/test-fs-open.js +++ b/test/simple/test-fs-open.js @@ -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); });