Skip to content

Commit cee62bb

Browse files
committed
src: expose Windows-only fs open flags
Signed-off-by: Kirill Saied <sayed.kirill@gmail.com>
1 parent ee64033 commit cee62bb

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
@@ -8767,10 +8767,36 @@ The following constants are meant for use with `fs.open()`.
87678767
is available on Windows operating systems only. On other operating systems,
87688768
this flag is ignored.</td>
87698769
</tr>
8770+
<tr>
8771+
<td><code>UV_FS_O_TEMPORARY</code></td>
8772+
<td>When set, the file is deleted automatically when the last handle to it
8773+
is closed. This flag is available on Windows operating systems only. On
8774+
other operating systems, this flag is ignored.</td>
8775+
</tr>
8776+
<tr>
8777+
<td><code>UV_FS_O_SHORT_LIVED</code></td>
8778+
<td>Hint that the file is short-lived, so the system avoids flushing it to
8779+
disk when possible. This flag is available on Windows operating systems
8780+
only. On other operating systems, this flag is ignored.</td>
8781+
</tr>
8782+
<tr>
8783+
<td><code>UV_FS_O_SEQUENTIAL</code></td>
8784+
<td>Hint that the file is accessed sequentially from beginning to end, to
8785+
optimize caching. This flag is available on Windows operating systems only.
8786+
On other operating systems, this flag is ignored.</td>
8787+
</tr>
8788+
<tr>
8789+
<td><code>UV_FS_O_RANDOM</code></td>
8790+
<td>Hint that the file is accessed randomly, to optimize caching. This flag
8791+
is available on Windows operating systems only. On other operating systems,
8792+
this flag is ignored.</td>
8793+
</tr>
87708794
</table>
87718795
87728796
On Windows, only `O_APPEND`, `O_CREAT`, `O_EXCL`, `O_RDONLY`, `O_RDWR`,
8773-
`O_TRUNC`, `O_WRONLY`, and `UV_FS_O_FILEMAP` are available.
8797+
`O_TRUNC`, `O_WRONLY`, `UV_FS_O_FILEMAP`, `UV_FS_O_TEMPORARY`,
8798+
`UV_FS_O_SHORT_LIVED`, `UV_FS_O_SEQUENTIAL`, and `UV_FS_O_RANDOM` are
8799+
available.
87748800
87758801
##### File type constants
87768802

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)