Skip to content

Commit

Permalink
src,lib: expose memory file mapping flag
Browse files Browse the repository at this point in the history
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 authored and BridgeAR committed Sep 25, 2019
1 parent 97d8b33 commit 78af92d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/node_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-fs-fmap.js
Original file line number Diff line number Diff line change
@@ -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 78af92d

Please sign in to comment.