Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@cathodique/mmap-io
Advanced tools
This is a fork of @raygun-nickj/mmap-io, as the upstream repo is no longer maintained. (Plus, it is incompatible with the electron memory cage)
This version of mmap-io builds on Node v8-23, and provides binaries for Windows, macOS and Linux via @mapbox/node-pre-gyp.
mmap(2) / madvise(2) / msync(2) / mincore(2) for node.js revisited.
I needed shared memory mapping and came across @bnoordhuis module node-mmap, only to find that it didn't work with later versions of io.js, node.js and compatibles. So out of need I threw this together along with the functionality I found was missing in the node-mmap: advice and sync.
Strong temptations to re-order arguments to something more sane was kept at bay, and I kept it as mmap(2) and node-mmap for compatibility. Notable difference is the additional optional argument to pass a usage advise in the mapping stage. I've given advise and sync more practical arguments, out of a node.js perspective, compared to their C/C++ counterparts.
The flag constants have crooked names from C/C++ retained in order to make it straight forward for the user to search the net, and relate to man-pages.
This is my first node.js addon and after hours wasted reading up on V8 API I luckily stumbled upon Native Abstractions for Node. Makes life so much easier. Hot tip!
mmap-io is written in C++11 and LiveScript — although I love LS, it's more prudent to use TypeScript for a library, so I've rewritten that code.
It should be noted that mem-mapping is by nature potentially blocking, and should not be used in concurrent serving/processing applications, but rather has it's niche where multiple processes are working on the same giant sets of data (thereby sparing physical memory, and load times if the kernel does it's job for read ahead), preferably multiple readers and single or none concurrent writer, to not spoil the gains by shitloads of spin-locks, mutexes or such. And your noble specific use case of course.
yarn
in "package.json" — which may have failed builds for those not having it installed (and then not building "es-release"), and completely missing the point of getting rid of Makenpm run build
) (should only ever be needed if you clone from git and contribute)offs_t
changed to size_t
because of bitwidth goofyness. Thanks to @bmarkivForceSet
to DefineOwnProperty
incore
fix for Mac OS. Thanks to @rustyconoverincore
added. Thanks to @rustyconoverhuman_errors
, ls
only, build
only, etc. (useful if you wanna hack the module)Use npm or git.
npm install @raygun-nickj/mmap-io
git clone https://github.com/Widdershin/mmap-io.git
cd mmap-io
npm install
npm build
Note: All code in examples are in LiveScript
# Following code is plastic fruit; not t[ae]sted...
mmap = require "mmap-io"
fs = require "fs"
some-file = "./foo.bar"
fd = fs.open-sync some-file, "r"
fd-w = fs.open-sync some-file, "r+"
# In the following comments:
# - `[blah]` denotes optional argument
# - `foo = x` denotes default value for argument
size = fs.fstat-sync(fd).size
rx-prot = mmap.PROT_READ .|. mmap.PROT_EXECUTE
priv = mmap.MAP_SHARED
# map( size, protection, privacy, fd [, offset = 0 [, advise = 0]] ) -> Buffer
buffer = mmap.map size, rx-prot, priv, fd
buffer2 = mmap.map size, mmap.PROT_READ, priv, fd, 0, mmap.MADV_SEQUENTIAL
w-buffer = mmap.map size, mmap.PROT_WRITE, priv, fd-w
# advise( buffer, advise ) -> void
# advise( buffer, offset, length, advise ) -> void
mmap.advise w-buffer, mmap.MADV_RANDOM
# sync( buffer ) -> void
# sync( buffer, offset, length ) -> void
# sync( buffer, is-blocking-sync[, do-page-invalidation = false] ) -> void
# sync( buffer, offset = 0, length = buffer.length [, is-blocking-sync = false [, do-page-invalidation = false]] ) -> void
mmap.sync w-buffer
mmap.sync w-buffer, true
mmap.sync w-buffer, 0, size
mmap.sync w-buffer, 0, size, true
mmap.sync w-buffer, 0, size, true, false
# incore( buffer ) -> [ unmapped-pages Int, mapped-pages Int ]
core-stats = mmap.incore buffer
Offset
, and in some cases length
needs to be a multiple of mmap-io.PAGESIZE (which commonly is 4096)fix-{ISSUE_NUMBER}-human-readable-descr-here
or feature-this-and-that
for your work@ozra
, so that
GitHub adds a notification to the "participating" list (less risk I miss it)
`npm test
FAQs
io.js/node.js mmap bindings re-revisited.
We found that @cathodique/mmap-io demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.