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

great-big-file-reader

v1.0.4

Published

Uses the node addon api to provide native handling of large files using mmap. It provides an interface to create a buffer into the file at specified offsets and lengths, avoiding issues when the file is bigger than the maximum Node buffer size.

Downloads

15

Readme

Great Big File Reader

The Great Big File Reader is an npm plugin that provides an efficient way to read large files in Node.js using memory mapping (mmap). This plugin allows you to mmap read-only files into buffers, making it ideal for working with extremely large files. Since node.js has a limit on the size of its Buffer objects of about 1Gb (32-bit architectures) and 4Gb (64-bit architectures) it is not possible to simply return a Buffer that lets you read the whole memory mapped file, if it exceeds those sizes.

With Great Big File Reader you can acquire as many Buffers as you want, each with an individual offset into the file and length (where length is limited to the Buffer size limits mentioned above).

Technical notes

node.js does not expose the memory map (mmap) operating system commands and leaves it to third party libraries like this one. Once a file is memory mapped, accessing it will cause blocking IO and/or page faults whenever the OS feels it needs to do so.

The code is written in C++ and uses the https://github.com/nodejs/node-addon-api which is a C++ friendly wrapper around the stable C interface of the Node-API. This provides a nice compromise between performance and language facility.

Features

  • Efficient read-only access to large files using mmap.
  • Not limited by node's buffer.constants.MAX_LENGTH
  • Easy integration with Node.js applications.

Compatibility

Since this uses the linux, bsd mmap feature, it does not currently work on the Windows operating system.

Installation

Install the Great Big File Reader plugin using npm:

npm install great-big-file-reader

Usage

Here's an example demonstrating how to use the Great Big File Reader in your Node.js application:

Note there are some interface improvements needed before this usable as a package.

import { MMapping } from '../lib/index.js';  

async function example(filePath) {
  try {
    const fileHandle = await fs.open(filePath, 'r');

    let mmapping = new MMapping(filePath, fileHandle.fd);

    // open a buffer at the first 1kb
    let buffer = mmapping.getBuffer(0n, 1024);
    let first = buffer.readBigUInt64LE(0);
    let last = buffer.readBigUint64LE(1024 - 8);

    // you can open multiple buffers with different offsets
    // and lengths. let them go out of scope to be gc'd

    await fileHandle.close();
    console.log('File closed successfully.');
  } catch (error) {
    console.error('Error caught: ', error);
  }
}

Contributing

Contributions are welcome! If you have suggestions, bug reports, or feature requests, please open an issue or submit a pull request.

License

This project is licensed under the ISC License.

Copyright

Copyright 2023 Justin Heyes-Jones. All Rights Reserved.