diff --git a/doc/api/fs.md b/doc/api/fs.md index 8077c533f854d2..2f1ce3f4876d2a 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -5031,6 +5031,12 @@ The following constants are meant for use with `fs.open()`. O_NONBLOCK Flag indicating to open the file in nonblocking mode when possible. + + UV_FS_O_FILEMAP + 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. + ### File Type Constants diff --git a/src/node_constants.cc b/src/node_constants.cc index 7c9e4ce276112b..68af221b60aa65 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -1127,6 +1127,8 @@ void DefineSystemConstants(Local 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 diff --git a/test/parallel/test-fs-fmap.js b/test/parallel/test-fs-fmap.js new file mode 100644 index 00000000000000..4b21ce8d95a12f --- /dev/null +++ b/test/parallel/test-fs-fmap.js @@ -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);