
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
memory-mapped-files
Advanced tools
Loading and mapping files into the memory using native code, allowing workers to access the files without redundant reads from disk.
Native
.node
addon for node.js written in C#.
Memory-mapped files offer a significant performance benefit over standard file access. It reduces the number of times the application must access the disk (which is slow compared to memory). In case you use thread workers, you can share the memory-mapped files between them, so you will also reduce the number of redundant file reads.
Native file reading is much faster than reading from a node.js. Memory-mapped files are intended mainly for workers so it creates TCP server that holds the files; Workers transfer the files over the network so it slows it down a little, but it is still much faster than reading from a node.js.
You can start the cache server in the background using the startCacheServer
function.
import { startCacheServer } from "memory-mapped-files";
startCacheServer("./working/directory");
You can also stop the cache server using the stopCacheServer
function.
stopCacheServer();
Second parameter of the startCacheServer
is an array of glob patterns that specify which files from the working directory should be cached.
import { startCacheServer } from "memory-mapped-files";
startCacheServer("./working/directory", ["**/*.ts"]);
Default value glob is **/*
, so all the files from working directory are cached.
Memory-mapped files does not track changes in the working directory. File deletions or changes are not reflected in the cache. You can change the files using the client (not fully implemented yet).
You can read the file using the getFile
and getFileAsync
methods on the Client
.
File paths should be relative from the working directory.
Each client creates a new TCP connection to the cache server, so it is recommended to create a single client and reuse it. One client should not do parallel requests; multiple clients can.
import { createClient } from "memory-mapped-files";
const client = createClient();
// Sync read
client.getFile("some-dir/index.ts");
// Async read
await client.getFileAsync("some-dir/index.ts");
client.dispose();
You should call the dispose method when you are done with the client.
You can do it manually or use the new using
keyword from TS 5.2, see the release note.
import { createClient } from "memory-mapped-files";
const client = createClient();
client.getFile("some-dir/index.ts");
client.dispose();
or
import { createClient } from "memory-mapped-files";
using client = createClient();
client.getFile("some-dir/index.ts");
FAQs
Loading and mapping files into the memory using native code, allowing workers to access the files without redundant reads from disk.
We found that memory-mapped-files demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.