Skip to content
Permalink
Browse files

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 <info@bnoordhuis.nl>
Reviewed-By: Ron Korving <ron@ronkorving.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
joaocgreis committed Aug 21, 2019
1 parent 9a436d1 commit 902c9fac194d06aec5fd5307a6712c39a6da18a7
Showing with 37 additions and 0 deletions.
  1. +6 −0 doc/api/fs.md
  2. +2 −0 src/node_constants.cc
  3. +29 −0 test/parallel/test-fs-fmap.js
@@ -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
@@ -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);

0 comments on commit 902c9fa

Please sign in to comment.
You can’t perform that action at this time.