Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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

  • Loading branch information
magicmonkey authored and bnoordhuis committed May 15, 2012
1 parent 643f00d commit dfcdd5b8aada95baf4c8365eb92f6507049b22ea
Showing with 18 additions and 1 deletion.
  1. +7 −0 doc/api/fs.markdown
  2. +2 −0 lib/fs.js
  3. +9 −1 test/simple/test-fs-open.js
@@ -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).

@@ -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
@@ -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);
});

2 comments on commit dfcdd5b

@mscdex

This comment has been minimized.

Copy link

mscdex replied May 15, 2012

Documentation for 'rs+' is missing?

@magicmonkey

This comment has been minimized.

Copy link
Author

magicmonkey replied May 16, 2012

Good point, oversight on my part - I've added docs in a new pull request (3274).

Please sign in to comment.
You can’t perform that action at this time.