Skip to content

Commit 78af92d

Browse files
joaocgreisBridgeAR
authored andcommitted
src,lib: expose memory file mapping flag
Support for UV_FS_O_FILEMAP was added in libuv in version 1.31.0. This exposes the flag in fs.constants. Refs: libuv/libuv#2295 PR-URL: #29260 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ron Korving <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 97d8b33 commit 78af92d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

doc/api/fs.md

+6
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,12 @@ The following constants are meant for use with `fs.open()`.
50315031
<td><code>O_NONBLOCK</code></td>
50325032
<td>Flag indicating to open the file in nonblocking mode when possible.</td>
50335033
</tr>
5034+
<tr>
5035+
<td><code>UV_FS_O_FILEMAP</code></td>
5036+
<td>When set, a memory file mapping is used to access the file. This flag
5037+
is available on Windows operating systems only. On other operating systems,
5038+
this flag is ignored.</td>
5039+
</tr>
50345040
</table>
50355041

50365042
### File Type Constants

src/node_constants.cc

+2
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,8 @@ void DefineSystemConstants(Local<Object> target) {
11271127
NODE_DEFINE_CONSTANT(target, O_EXCL);
11281128
#endif
11291129

1130+
NODE_DEFINE_CONSTANT(target, UV_FS_O_FILEMAP);
1131+
11301132
#ifdef O_NOCTTY
11311133
NODE_DEFINE_CONSTANT(target, O_NOCTTY);
11321134
#endif

test/parallel/test-fs-fmap.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const fs = require('fs');
5+
const join = require('path').join;
6+
7+
const {
8+
O_CREAT = 0,
9+
O_RDONLY = 0,
10+
O_TRUNC = 0,
11+
O_WRONLY = 0,
12+
UV_FS_O_FILEMAP = 0
13+
} = fs.constants;
14+
15+
const tmpdir = require('../common/tmpdir');
16+
tmpdir.refresh();
17+
18+
// Run this test on all platforms. While UV_FS_O_FILEMAP is only available on
19+
// Windows, it should be silently ignored on other platforms.
20+
21+
const filename = join(tmpdir.path, 'fmap.txt');
22+
const text = 'Memory File Mapping Test';
23+
24+
const mw = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY;
25+
const mr = UV_FS_O_FILEMAP | O_RDONLY;
26+
27+
fs.writeFileSync(filename, text, { flag: mw });
28+
const r1 = fs.readFileSync(filename, { encoding: 'utf8', flag: mr });
29+
assert.strictEqual(r1, text);

0 commit comments

Comments
 (0)