🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

random-access-database

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-access-database

Store fixed size values in an abstract-random-access compatible storage provider

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

random-access-database

Store fixed size values in an abstract-random-access compatible storage provider

npm install random-access-database

build status

Usage

var rad = require('random-access-database')
var raf = require('random-access-file')

var db = rad(raf('db'), {valueLength: 5})

db.put(0, 'hello', function (err) {
  if (err) throw err
  db.get(0, function (err, val) {
    if (err) throw err
    console.log('stored at 0:', val)
  })
})

API

var db = rad(storage, options)

Create a new databae. storage should be an abstract-random-access compatible storage provider. Options include

{
  valueEncoding: encodeValuesUsingThisEncoding,
  valueLength: lengthOfAllValues,
  offset: functionThatReturnsValueOffset
}

You must either set the valueLength of offset option. The offset option is called with the numeric index of a value and should return the byte offset of this value.

db.put(index, value, [callback])

Insert a value in the database.

db.get(index, callback)

Retrieve a value from the database. Callback is called with (err, value).

db.del(index, [callback])

Delete a value from the database. Will blank it out in the underlying storage.

License

MIT

FAQs

Package last updated on 18 Aug 2016

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