Skip to content

Commit 925efac

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 e4ab7ce commit 925efac

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
@@ -1794,11 +1794,17 @@ The file is created if it does not exist.
17941794

17951795
* `'ax'` - Like `'a'` but fails if `path` exists.
17961796

1797+
* `'as'` - Open file for appending in synchronous mode.
1798+
The file is created if it does not exist.
1799+
17971800
* `'a+'` - Open file for reading and appending.
17981801
The file is created if it does not exist.
17991802

18001803
* `'ax+'` - Like `'a+'` but fails if `path` exists.
18011804

1805+
* `'as+'` - Open file for reading and appending in synchronous mode.
1806+
The file is created if it does not exist.
1807+
18021808
`mode` sets the file mode (permission and sticky bits), but only if the file was
18031809
created. It defaults to `0o666` (readable and writable).
18041810

lib/internal/fs.js

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

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

5559
throw new Error('Unknown file open flag: ' + flag);

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)