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 🙏

© 2024 – Pkg Stats / Ryan Hefner

memory-mapped-files

v0.1.1

Published

Loading and mapping files into the memory using native code, allowing workers to access the files without redundant reads from disk.

Downloads

6

Readme

Memory-Mapped Files

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.

Start the Cache Server

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.

Tracking changes

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).

Read File

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

Disposing Client

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");