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: https://github.com/libuv/libuv/pull/2295 PR-URL: https://github.com/nodejs/node/pull/29260 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
9a436d19f3
commit
902c9fac19
@ -5031,6 +5031,12 @@ The following constants are meant for use with `fs.open()`.
|
||||
<td><code>O_NONBLOCK</code></td>
|
||||
<td>Flag indicating to open the file in nonblocking mode when possible.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>UV_FS_O_FILEMAP</code></td>
|
||||
<td>When set, a memory file mapping is used to access the file. This flag
|
||||
is available on Windows operating systems only. On other operating systems,
|
||||
this flag is ignored.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### File Type Constants
|
||||
|
@ -1127,6 +1127,8 @@ void DefineSystemConstants(Local<Object> target) {
|
||||
NODE_DEFINE_CONSTANT(target, O_EXCL);
|
||||
#endif
|
||||
|
||||
NODE_DEFINE_CONSTANT(target, UV_FS_O_FILEMAP);
|
||||
|
||||
#ifdef O_NOCTTY
|
||||
NODE_DEFINE_CONSTANT(target, O_NOCTTY);
|
||||
#endif
|
||||
|
29
test/parallel/test-fs-fmap.js
Normal file
29
test/parallel/test-fs-fmap.js
Normal file
@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const join = require('path').join;
|
||||
|
||||
const {
|
||||
O_CREAT = 0,
|
||||
O_RDONLY = 0,
|
||||
O_TRUNC = 0,
|
||||
O_WRONLY = 0,
|
||||
UV_FS_O_FILEMAP = 0
|
||||
} = fs.constants;
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
tmpdir.refresh();
|
||||
|
||||
// Run this test on all platforms. While UV_FS_O_FILEMAP is only available on
|
||||
// Windows, it should be silently ignored on other platforms.
|
||||
|
||||
const filename = join(tmpdir.path, 'fmap.txt');
|
||||
const text = 'Memory File Mapping Test';
|
||||
|
||||
const mw = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY;
|
||||
const mr = UV_FS_O_FILEMAP | O_RDONLY;
|
||||
|
||||
fs.writeFileSync(filename, text, { flag: mw });
|
||||
const r1 = fs.readFileSync(filename, { encoding: 'utf8', flag: mr });
|
||||
assert.strictEqual(r1, text);
|
Loading…
x
Reference in New Issue
Block a user