mmap-io icon indicating copy to clipboard operation
mmap-io copied to clipboard

Add minimal node example to Readme

Open ocramz opened this issue 3 years ago • 0 comments

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();
                ...
            })
        })

ocramz avatar Nov 05 '22 10:11 ocramz