npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@k13engineering/po6-mmap

v0.0.6

Published

Map memory to buffers via mmap

Readme

node-po6-mmap

A Node.js library for memory-mapped file I/O using the mmap system call. This package provides a TypeScript-first interface for mapping files into memory with automatic resource management and garbage collection safety.

Features

  • 🗺️ Map files into memory using the mmap syscall
  • 🔒 Support for shared and private mappings
  • ⚡ Zero-copy access to file data via Uint8Array
  • 🛡️ Automatic detection of unmapped buffers during garbage collection
  • 📦 TypeScript-first with full type definitions
  • 🔧 Flexible memory protection flags (read, write, execute)

Installation

npm install @k13engineering/po6-mmap

Usage

import { mmapFd, determinePageSize } from "@k13engineering/po6-mmap";
import nodeFs from "node:fs";

const fd = nodeFs.openSync("/dev/zero", "r+");

const length = determinePageSize();

const { errno, buffer } = mmapFd({
  fd,
  mappingVisibility: "MAP_PRIVATE",
  memoryProtectionFlags: {
    PROT_READ: true,
    PROT_WRITE: false,
    PROT_EXEC: false,
  },
  genericFlags: {},
  offsetInFd: 0,
  length,
});

nodeFs.closeSync(fd);

if (errno !== undefined) {
  throw Error(`mmapFd failed with errno ${errno}`);
}

console.log(`mapped buffer of length ${buffer.length} at address 0x${buffer.address.toString(16)}`);
console.log(`buffer:`, buffer);

buffer.unmap();

API

mmapFd(options)

Maps a file descriptor into memory.

Parameters:

  • fd (number): File descriptor to map
  • mappingVisibility ("MAP_SHARED" | "MAP_PRIVATE"): Mapping visibility
    • MAP_SHARED: Changes are shared with other processes
    • MAP_PRIVATE: Changes are private (copy-on-write)
  • memoryProtectionFlags (object): Memory protection flags
    • PROT_READ (boolean): Allow read access
    • PROT_WRITE (boolean): Allow write access
    • PROT_EXEC (boolean): Allow execution
  • genericFlags (object): Additional flags
    • MAP_32BIT (boolean): Map into 32-bit address space
    • MAP_LOCKED (boolean): Lock pages in memory
    • MAP_NORESERVE (boolean): Don't reserve swap space
  • offsetInFd (number): Offset in file (must be page-aligned)
  • length (number): Length of mapping in bytes

Returns: Object with either:

  • { errno: number, buffer: undefined } on error
  • { errno: undefined, buffer: TMemoryMappedBuffer } on success

Note: Not all mmap options are currently exposed. Additional flags and options may be added in future versions.

TMemoryMappedBuffer

A Uint8Array with additional properties:

  • address (bigint): Memory address of the mapping
  • unmap() (function): Unmaps the memory region

Important: Always call unmap() when done to avoid memory leaks. If a buffer is garbage collected without being unmapped, the library will throw an uncaught exception.

determinePageSize()

Returns the system page size (currently hardcoded to 4096).

Memory Safety

This library includes a finalization registry that detects if a memory-mapped buffer is garbage collected without calling unmap(). If this happens, a MemoryMappedBufferGarbageCollectedWithoutUnmapError is thrown to prevent silent memory leaks.

Always ensure you call unmap() on buffers when you're done with them:

const result = mmapFd({ /* ... */ });
if (result.errno === undefined) {
  try {
    // Use result.buffer
  } finally {
    result.buffer.unmap(); // Always unmap in finally block
  }
}

License

See LICENSE file.