Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f9dc8ed2ca
Fetching contributors…

Cannot retrieve contributors at this time

70 lines (51 sloc) 1.867 kb


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

** This module is no longer maintained. **


Through npm:

npm install mmap

Or compile it from source with this one-liner:

node-waf configure build install


buffer =, 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.


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.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.

Bugs and 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. :-)

  • Reading from and writing to memory-mapped files is a potentially blocking operation. Do not use this module in performance critical code. Better yet, don't use this module at all.

Jump to Line
Something went wrong with that request. Please try again.