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

shared-file-view

v1.0.5

Published

A Node.js add-on that loads a text file into a shared memory segment.

Downloads

9

Readme

Shared File View

Tests passing NPM version

SharedFileView is a Node.js add-on that loads a file into a shared memory segment, allowing multiple processes to access the same memory data quickly and efficiently, as a JavaScript array. The returned array is read-only.

SharedFileView is designed for speed and minimal memory usage. By using shared memory, SharedFileView eliminates the need to copy data between processes, resulting in blazing fast performance. Additionally, SharedFileView uses the minimum memory allocation possible to load the text file into memory, ensuring that your system resources are used efficiently.

Requirements

Boost libraries (^1.81) installed on the system. Installation will fail otherwise.

Follow this guide to install it.

Installation

npm install shared-file-view

Usage

Creating a SharedFileView

First create a SharedFileView for a file, using the SharedFileView.Create static method. This method is asynchronous, so you can pass a callback function as the second argument to be called when the SharedFileView is actually created.

const { SharedFileView } = require("shared-file-view");

SharedFileView.Create("/path/to/file.txt", (err) => {
	if (err) {
		console.error(err);
	} else {
		console.log("SharedFileView created");
	}
});

Reading from an existing SharedFileView

To retrieve an array of lines from a file, use the SharedFileView.ArrayFrom constructor. This method returns a JavaScript array that you can use to access any line of the file.

const { SharedFileView } = require("shared-file-view");

const filePath = "/path/to/file.txt";
const sharedFileView = new SharedFileView.ArrayFrom(filePath);

console.log(sharedFileView[0]); // Prints the first line of the file
console.log(sharedFileView[1]); // Prints the second line of the file

Checking if a SharedFileView Exists

To check if a SharedFileView for a file has already been created, use the SharedFileView.Exists static method. This method returns a boolean indicating whether the SharedFileView exists.

const { SharedFileView } = require("shared-file-view");

const filePath = "/path/to/file.txt";
const exists = SharedFileView.Exists(filePath);

console.log(exists); // Prints true if a SharedFileView exists, false otherwise

Removing a SharedFileView

To remove a SharedFileView from memory and free up system resources, use the SharedFileView.Remove static method.

const { SharedFileView } = require("shared-file-view");

const filePath = "/path/to/file.txt";
SharedFileView.Remove(filePath, (err) => {
	if (err) {
		console.error(err);
	} else {
		console.log("SharedFileView removed");
	}
});

License

SharedFileView is licensed under the MIT License. See the LICENSE file for details.

Credits

I would like to thank the following individuals for their contributions to SharedFileView:

  • Seth Heeren (@sehe), for providing the original approach that underlie SharedFileView.
  • Allen Luce (@allenluce), for creating the mmap-object package that inspired SharedFileView.

Without the the contributions of Seth Heeren and the pioneering work of Allen Luce, SharedFileView would not be possible. I am grateful for their efforts and for making their work available under the MIT License.