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

random-access-idb-with-overlay

v1.0.21

Published

A combined storage solution layering RandomAccessLayeredStorage over random-access-idb.

Downloads

15

Readme

random-access-idb-with-overlay

License npm version npm downloads

random-access-idb-with-overlay (RAIWO) is a robust and efficient storage solution that layers RandomAccessLayeredStorage over random-access-idb. This combination enables seamless and optimized in-browser storage with overlay capabilities, leveraging the strengths of both libraries to provide a flexible and high-performance storage mechanism for your web applications.

Table of Contents

Features

  • Layered Storage: Combines the capabilities of RandomAccessLayeredStorage with random-access-idb for optimized storage performance.
  • In-Browser Storage: Utilizes IndexedDB for persistent in-browser storage, ensuring data remains across sessions.
  • Overlay Mechanism: Efficiently manages data overlays, reducing redundancy and improving access speeds.
  • Easy Integration: Simple and intuitive API for seamless integration into your projects.
  • Flexible Configuration: Allows customization of both the underlying random-access-idb and the layering behavior through configuration options.
  • Compatibility: Supports both CommonJS and ES Modules for flexible usage in various environments.

Installation

You can install random-access-idb-with-overlay via npm:

# Using npm
npm install random-access-idb-with-overlay

Usage

Basic Example

Here's a straightforward example demonstrating how to use random-access-idb-with-overlay in your project:

// Import the library
import RandomAccessIdbWithOverlay from 'random-access-idb-with-overlay';

// Create an instance with a unique filename
const storage = new RandomAccessIdbWithOverlay('my-storage-file');

// Writing data
const bufferToWrite = new Uint8Array([1, 2, 3, 4, 5]);
const offset = 0; // Start at the beginning

storage.write(offset, bufferToWrite, (err) => {
  if (err) {
    console.error('Write failed:', err);
  } else {
    console.log('Data written successfully!');
  }
});

// Reading data
const length = 5; // Number of bytes to read

storage.read(offset, length, (err, data) => {
  if (err) {
    console.error('Read failed:', err);
  } else {
    console.log('Data read:', data);
  }
});

Advanced Configuration

You can customize random-access-idb-with-overlay by passing additional configuration options to fine-tune both the underlying random-access-idb and the layering behavior. The configuration object is divided into two parts:

  • raiConfig: Configuration options specific to random-access-idb.
  • layeredConfig: Configuration options specific to RandomAccessLayeredStorage.
import RandomAccessIdbWithOverlay from 'random-access-idb-with-overlay';

// Configuration options
const config = {
    layeredConfig, // object containing random-access-layered-storage configuration
    ... // the rest of the config options are added to random-access-idb
};

const storage = new RandomAccessIdbWithOverlay('my-custom-storage', config);

// Proceed with read/write operations as usual

Notes:

  • raiConfig: This object contains configuration options passed directly to random-access-idb. You can customize buffer sizes, concurrency settings, and other IndexedDB-specific options. For detailed configuration options, refer to the random-access-idb documentation.

  • layeredConfig: This object contains configuration options passed to RandomAccessLayeredStorage. You can adjust cache sizes, set eviction policies, and configure other layering behaviors. For detailed configuration options, refer to the RandomAccessLayeredStorage documentation.

API Reference

RandomAccessIdbWithOverlay

A class that combines RandomAccessLayeredStorage with random-access-idb for optimized in-browser storage with overlay capabilities.

Constructor

new RandomAccessIdbWithOverlay(fileName, config = {})
  • Parameters:

    • fileName (string): The name of the storage file. This name is used as the key in IndexedDB to store the data.
    • config (object, optional): Configuration options for the storage.
      • raiConfig (object, optional): Configuration options specific to random-access-idb.
      • layeredConfig (object, optional): Configuration options specific to RandomAccessLayeredStorage.
  • Throws:

    • Error: If fileName is not a non-empty string.
  • Usage:

    const storage = new RandomAccessIdbWithOverlay('my-storage-file', {
      layeredConfig: { /* RandomAccessLayeredStorage options */ },
      /* random-access-idb options */
      ...raiConfig
    });

License

This project is licensed under the MIT License.