Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

random-access-idb-with-overlay

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-access-idb-with-overlay

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

  • 1.0.21
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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.

Keywords

FAQs

Package last updated on 16 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc