Browse Source

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

v0.9.1-release
Kevin Bowman 13 years ago
committed by Ben Noordhuis
parent
commit
dfcdd5b8aa
  1. 7
      doc/api/fs.markdown
  2. 2
      lib/fs.js
  3. 10
      test/simple/test-fs-open.js

7
doc/api/fs.markdown

@ -270,6 +270,13 @@ An exception occurs if the file does not exist.
* `'r+'` - Open file for reading and writing. * `'r+'` - Open file for reading and writing.
An exception occurs if the file does not exist. 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. * `'w'` - Open file for writing.
The file is created (if it does not exist) or truncated (if it exists). The file is created (if it does not exist) or truncated (if it exists).

2
lib/fs.js

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

10
test/simple/test-fs-open.js

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

Loading…
Cancel
Save