Skip to content

Commit 985aa07

Browse files
authored
src: expose Windows-only fs open flags
Signed-off-by: Kirill Saied <sayed.kirill@gmail.com> PR-URL: #64775 Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 9caf674 commit 985aa07

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

doc/api/fs.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8789,10 +8789,36 @@ The following constants are meant for use with `fs.open()`.
87898789
is available on Windows operating systems only. On other operating systems,
87908790
this flag is ignored.</td>
87918791
</tr>
8792+
<tr>
8793+
<td><code>UV_FS_O_TEMPORARY</code></td>
8794+
<td>When set, the file is deleted automatically when the last handle to it
8795+
is closed. This flag is available on Windows operating systems only. On
8796+
other operating systems, this flag is ignored.</td>
8797+
</tr>
8798+
<tr>
8799+
<td><code>UV_FS_O_SHORT_LIVED</code></td>
8800+
<td>Hint that the file is short-lived, so the system avoids flushing it to
8801+
disk when possible. This flag is available on Windows operating systems
8802+
only. On other operating systems, this flag is ignored.</td>
8803+
</tr>
8804+
<tr>
8805+
<td><code>UV_FS_O_SEQUENTIAL</code></td>
8806+
<td>Hint that the file is accessed sequentially from beginning to end, to
8807+
optimize caching. This flag is available on Windows operating systems only.
8808+
On other operating systems, this flag is ignored.</td>
8809+
</tr>
8810+
<tr>
8811+
<td><code>UV_FS_O_RANDOM</code></td>
8812+
<td>Hint that the file is accessed randomly, to optimize caching. This flag
8813+
is available on Windows operating systems only. On other operating systems,
8814+
this flag is ignored.</td>
8815+
</tr>
87928816
</table>
87938817
87948818
On Windows, only `O_APPEND`, `O_CREAT`, `O_EXCL`, `O_RDONLY`, `O_RDWR`,
8795-
`O_TRUNC`, `O_WRONLY`, and `UV_FS_O_FILEMAP` are available.
8819+
`O_TRUNC`, `O_WRONLY`, `UV_FS_O_FILEMAP`, `UV_FS_O_TEMPORARY`,
8820+
`UV_FS_O_SHORT_LIVED`, `UV_FS_O_SEQUENTIAL`, and `UV_FS_O_RANDOM` are
8821+
available.
87968822
87978823
##### File type constants
87988824

src/node_constants.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,12 @@ void DefineFsConstants(Local<Object> target) {
11371137
NODE_DEFINE_CONSTANT(target, O_EXCL);
11381138
#endif
11391139

1140-
NODE_DEFINE_CONSTANT(target, UV_FS_O_FILEMAP);
1140+
// Windows-only open flags honored by libuv. They are 0 on other platforms.
1141+
NODE_DEFINE_CONSTANT(target, UV_FS_O_FILEMAP);
1142+
NODE_DEFINE_CONSTANT(target, UV_FS_O_TEMPORARY);
1143+
NODE_DEFINE_CONSTANT(target, UV_FS_O_SHORT_LIVED);
1144+
NODE_DEFINE_CONSTANT(target, UV_FS_O_SEQUENTIAL);
1145+
NODE_DEFINE_CONSTANT(target, UV_FS_O_RANDOM);
11411146

11421147
#ifdef O_NOCTTY
11431148
NODE_DEFINE_CONSTANT(target, O_NOCTTY);

test/parallel/test-fs-constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const knownFsConstantNames = [
3535
'O_CREAT',
3636
'O_EXCL',
3737
'UV_FS_O_FILEMAP',
38+
'UV_FS_O_TEMPORARY',
39+
'UV_FS_O_SHORT_LIVED',
40+
'UV_FS_O_SEQUENTIAL',
41+
'UV_FS_O_RANDOM',
3842
'O_NOCTTY',
3943
'O_TRUNC',
4044
'O_APPEND',

0 commit comments

Comments
 (0)