Socket
Book a DemoInstallSign in
Socket

multi-random-access

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multi-random-access

An abstract-random-access compliant instance that combines multiple other abstract-random-access instances into a single one.

latest
Source
npmnpm
Version
2.1.1
Version published
Weekly downloads
132
-40.81%
Maintainers
1
Weekly downloads
 
Created
Source

multi-random-access

An abstract-random-access compliant instance (API similar to random-access-file) that combines multiple other abstract-random-access instances into a single one.

npm install multi-random-access

build status

Usage

In the below example we'll create a multi-random-access instance that writes to different instances of random-access-memory, each containing 10 bytes of data.

var multi = require('multi-random-access')
var ram = require('random-access-memory')

var storage = multi(function (offset, cb) {
  var index = Math.floor(offset / 10)

  console.log('Creating new underlying storage')

  cb(null, {
    start: index * 10,
    end: index * 10 + 10,
    storage: ram()
  })
})

storage.write(0, Buffer('hello world'), function (err) {
  if (err) throw err
  storage.read(0, 11, function (err, buf) {
    if (err) throw err
    console.log(buf.toString())
  })
})

API

var storage = multi([options], open)

Create a new instance. open is a function that is called when a new storage instance is needed. A new instance is needed when a read or write happens in a byte range that has not been opened yet.

The signature for open is (offset, cb). You should call the callback with an object containing the following properties:

function open (offset, cb) {
  cb(null, {
    start: startByteOffset,
    end: endByteOffset,
    storage: abstractRandomAccessInstance
  })
}

Options include:

{
  limit: 16 // start closes old stores after this many was opened
}

License

MIT

FAQs

Package last updated on 25 Apr 2017

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