Skip to content

zacharygriffee/random-access-idb

Repository files navigation

random-access-idb


See: random-access-storage for the full api about what this library derives from.


Test it

In Node

npm test

In Browser


Installation

npm install @zacharygriffee/random-access-idb --save

Import

import rai from "@zacharygriffee/random-access-idb";

Improvements

  • Uses b4a for buffer operations
  • Implements del and truncate, and removes empty chunks from database with these operations
  • Extends with purge to delete a file from the database
  • Metadata that holds the chunkSize. IF you reopen a file that had a declared chunk size, it will open the file in that chunk size despite the configuration.
  • New blocking handlers for multiple tab support. If a file is open in one place, and another place tries to open the same file, use the blocking handlers to specify how to handle the conflict
  • Close now has a necessary reason to exist.

!!! NEW BEHAVIOR !!!

If you plan on using this cross-tab... It is now important to close the IDB file when you're done so that other tabs in the same origin can open the file.

Example

    import rai from "@zacharygriffee/random-access-idb";
    
    const file = rai("hello.txt");
    file.write(0, b4a.from("hello world"), (e) => {
        file.read(0, 5, (e, buffer) => {
            b4a.toString(buffer); // hello
        })
    });

Todo

  • Add a metadata for stats. Block/Chunk size.
  • Error handling and testing of errors
  • Multiple browser tab support (needs testing)

Distributed under the MIT license. See LICENSE for more information.

About

Random Access IDB modernized

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published