Skip to content

Commit 5426143

Browse files
SirR4TMayaLekova
authored andcommitted
fs: support as and as+ flags in stringToFlags()
PR-URL: nodejs#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 424f12f commit 5426143

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

doc/api/fs.md

+12
Original file line numberDiff line numberDiff line change
@@ -2019,11 +2019,17 @@ The file is created if it does not exist.
20192019

20202020
* `'ax'` - Like `'a'` but fails if `path` exists.
20212021

2022+
* `'as'` - Open file for appending in synchronous mode.
2023+
The file is created if it does not exist.
2024+
20222025
* `'a+'` - Open file for reading and appending.
20232026
The file is created if it does not exist.
20242027

20252028
* `'ax+'` - Like `'a+'` but fails if `path` exists.
20262029

2030+
* `'as+'` - Open file for reading and appending in synchronous mode.
2031+
The file is created if it does not exist.
2032+
20272033
`mode` sets the file mode (permission and sticky bits), but only if the file was
20282034
created. It defaults to `0o666` (readable and writable).
20292035

@@ -3920,11 +3926,17 @@ The file is created if it does not exist.
39203926

39213927
* `'ax'` - Like `'a'` but fails if `path` exists.
39223928

3929+
* `'as'` - Open file for appending in synchronous mode.
3930+
The file is created if it does not exist.
3931+
39233932
* `'a+'` - Open file for reading and appending.
39243933
The file is created if it does not exist.
39253934

39263935
* `'ax+'` - Like `'a+'` but fails if `path` exists.
39273936

3937+
* `'as+'` - Open file for reading and appending in synchronous mode.
3938+
The file is created if it does not exist.
3939+
39283940
`mode` sets the file mode (permission and sticky bits), but only if the file was
39293941
created. It defaults to `0o666` (readable and writable).
39303942

lib/internal/fs.js

+4
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,14 @@ function stringToFlags(flags) {
223223
case 'a' : return O_APPEND | O_CREAT | O_WRONLY;
224224
case 'ax' : // Fall through.
225225
case 'xa' : return O_APPEND | O_CREAT | O_WRONLY | O_EXCL;
226+
case 'as' : // Fall through.
227+
case 'sa' : return O_APPEND | O_CREAT | O_WRONLY | O_SYNC;
226228

227229
case 'a+' : return O_APPEND | O_CREAT | O_RDWR;
228230
case 'ax+': // Fall through.
229231
case 'xa+': return O_APPEND | O_CREAT | O_RDWR | O_EXCL;
232+
case 'as+': // Fall through.
233+
case 'sa+': return O_APPEND | O_CREAT | O_RDWR | O_SYNC;
230234
}
231235

232236
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)