Skip to content

Commit b055a43

Browse files
PickBasaduh95
authored andcommitted
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 d82a616 commit b055a43

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
@@ -8728,10 +8728,36 @@ The following constants are meant for use with `fs.open()`.
87288728
is available on Windows operating systems only. On other operating systems,
87298729
this flag is ignored.</td>
87308730
</tr>
8731+
<tr>
8732+
<td><code>UV_FS_O_TEMPORARY</code></td>
8733+
<td>When set, the file is deleted automatically when the last handle to it
8734+
is closed. This flag is available on Windows operating systems only. On
8735+
other operating systems, this flag is ignored.</td>
8736+
</tr>
8737+
<tr>
8738+
<td><code>UV_FS_O_SHORT_LIVED</code></td>
8739+
<td>Hint that the file is short-lived, so the system avoids flushing it to
8740+
disk when possible. This flag is available on Windows operating systems
8741+
only. On other operating systems, this flag is ignored.</td>
8742+
</tr>
8743+
<tr>
8744+
<td><code>UV_FS_O_SEQUENTIAL</code></td>
8745+
<td>Hint that the file is accessed sequentially from beginning to end, to
8746+
optimize caching. This flag is available on Windows operating systems only.
8747+
On other operating systems, this flag is ignored.</td>
8748+
</tr>
8749+
<tr>
8750+
<td><code>UV_FS_O_RANDOM</code></td>
8751+
<td>Hint that the file is accessed randomly, to optimize caching. This flag
8752+
is available on Windows operating systems only. On other operating systems,
8753+
this flag is ignored.</td>
8754+
</tr>
87318755
</table>
87328756
87338757
On Windows, only `O_APPEND`, `O_CREAT`, `O_EXCL`, `O_RDONLY`, `O_RDWR`,
8734-
`O_TRUNC`, `O_WRONLY`, and `UV_FS_O_FILEMAP` are available.
8758+
`O_TRUNC`, `O_WRONLY`, `UV_FS_O_FILEMAP`, `UV_FS_O_TEMPORARY`,
8759+
`UV_FS_O_SHORT_LIVED`, `UV_FS_O_SEQUENTIAL`, and `UV_FS_O_RANDOM` are
8760+
available.
87358761
87368762
##### File type constants
87378763

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)