Skip to content

Commit 607b33c

Browse files
SirR4TMylesBorins
authored andcommitted
fs: support as and as+ flags in stringToFlags()
PR-URL: #18801 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 49391a7 commit 607b33c

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

doc/api/fs.md

+6
Original file line numberDiff line numberDiff line change
@@ -2008,11 +2008,17 @@ The file is created if it does not exist.
20082008

20092009
* `'ax'` - Like `'a'` but fails if `path` exists.
20102010

2011+
* `'as'` - Open file for appending in synchronous mode.
2012+
The file is created if it does not exist.
2013+
20112014
* `'a+'` - Open file for reading and appending.
20122015
The file is created if it does not exist.
20132016

20142017
* `'ax+'` - Like `'a+'` but fails if `path` exists.
20152018

2019+
* `'as+'` - Open file for reading and appending in synchronous mode.
2020+
The file is created if it does not exist.
2021+
20162022
`mode` sets the file mode (permission and sticky bits), but only if the file was
20172023
created. It defaults to `0o666` (readable and writable).
20182024

lib/internal/fs.js

+4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ function stringToFlags(flags) {
4747
case 'a' : return O_APPEND | O_CREAT | O_WRONLY;
4848
case 'ax' : // Fall through.
4949
case 'xa' : return O_APPEND | O_CREAT | O_WRONLY | O_EXCL;
50+
case 'as' : // Fall through.
51+
case 'sa' : return O_APPEND | O_CREAT | O_WRONLY | O_SYNC;
5052

5153
case 'a+' : return O_APPEND | O_CREAT | O_RDWR;
5254
case 'ax+': // Fall through.
5355
case 'xa+': return O_APPEND | O_CREAT | O_RDWR | O_EXCL;
56+
case 'as+': // Fall through.
57+
case 'sa+': return O_APPEND | O_CREAT | O_RDWR | O_SYNC;
5458
}
5559

5660
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'flags', flags);

test/parallel/test-fs-open-flags.js

+4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ assert.strictEqual(stringToFlags('wx+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL);
5656
assert.strictEqual(stringToFlags('xw+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL);
5757
assert.strictEqual(stringToFlags('ax'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL);
5858
assert.strictEqual(stringToFlags('xa'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL);
59+
assert.strictEqual(stringToFlags('as'), O_APPEND | O_CREAT | O_WRONLY | O_SYNC);
60+
assert.strictEqual(stringToFlags('sa'), O_APPEND | O_CREAT | O_WRONLY | O_SYNC);
5961
assert.strictEqual(stringToFlags('ax+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
6062
assert.strictEqual(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
63+
assert.strictEqual(stringToFlags('as+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
64+
assert.strictEqual(stringToFlags('sa+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
6165

6266
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
6367
.split(' ')

0 commit comments

Comments
 (0)