mmap-io
mmap-io copied to clipboard
Add minimal node example to Readme
Hi, thank you for maintaining this! I've just used it successfully for building a data labeling webapp, where the datasets are 100s of MB each.
I've cobbled this together from a stackoverflow answer (https://stackoverflow.com/questions/23747892/how-would-i-design-and-implement-a-non-blocking-memory-mapping-module-for-node-j), and perhaps others would enjoy something like as a starter example in the README too
var mmap = require('mmap-io')
var fs = require('fs')
fs.open('/file/path', 'r', (err, fd) => {
fs.fstat(fd, (err, stats) => {
var buf = mmap.map(stats.size, mmap.PROT_READ, mmap.MAP_SHARED, fd, 0);
const start = 0;
const len = 100;
var line = buf.slice(start, len).toString();
...
})
})