Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
mmap(2) bindings for node.js
branch: fastbuffer-com…

This branch is 1 commit ahead, 3 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
LICENSE
README.md
mmap.cc
package.json
test.js
wscript

README.md

node-mmap

mmap(2) bindings for node.js - stop slurping, start mapping.

Installing

Through npm:

npm install mmap

Or compile it from source with this one-liner:

node-waf configure build install

Usage

buffer = mmap.map(n_bytes, protection, flags, fd, offset);
n_bytes The number of bytes to map into memory.
protection Memory protection: either PROT_NONE or a bitwise OR of PROT_READ, PROT_WRITE and PROT_EXEC.
flags Flags: either MAP_SHARED or MAP_PRIVATE.
fd File descriptor.
offset File offset. Must be either zero or a multiple of mmap.PAGESIZE.

See the man page for more details.

Examples

Map a file into memory:

fs = require('fs'), mmap = require('mmap');
fd = fs.openSync('/path/to/file', 'r');
size = fs.fstatSync(fd).size;
buffer = mmap.map(size, mmap.PROT_READ, mmap.MAP_SHARED, fd, 0);
// calculate faux checksum
var checksum = 0;
for (var i = 0; i < buffer.length; i++) {
  checksum ^= buffer[i];
}

The file is automatically unmapped when the buffer object is garbage collected.

Limitations

  • Specifying the memory address is not implemented. I couldn't think of a reason why you would want to do that from JavaScript. Convince me otherwise. :-)
Something went wrong with that request. Please try again.