# multi-random-access

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

Latest version **2.1.1** (published 2017-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install multi-random-access
pnpm add multi-random-access
yarn add multi-random-access
bun add multi-random-access
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2017-04-25 |
| First published | 2016-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/multi-random-access
- Repository: https://github.com/mafintosh/multi-random-access
- Issues: https://github.com/mafintosh/multi-random-access/issues
- npm.io page: https://npm.io/package/multi-random-access

## Dependencies (3)

- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [abstract-random-access](https://npm.io/package/abstract-random-access.md) ^1.1.2
- [sorted-array-functions](https://npm.io/package/sorted-array-functions.md) ^1.0.0

## Recent versions

- 2.1.1 (latest) — 2017-04-25
- 2.1.0 — 2017-04-20
- 2.0.3 — 2016-10-24
- 2.0.2 — 2016-10-21
- 2.0.1 — 2016-10-20
- 2.0.0 — 2016-10-06
- 1.0.0 — 2016-08-01

## README

# multi-random-access

An [abstract-random-access](https://github.com/juliangruber/abstract-random-access) compliant instance (API similar to [random-access-file](https://github.com/mafintosh/random-access-file)) that combines multiple other abstract-random-access instances into a single one.

```
npm install multi-random-access
```

[![build status](http://img.shields.io/travis/mafintosh/multi-random-access.svg?style=flat)](http://travis-ci.org/mafintosh/multi-random-access)

## Usage

In the below example we'll create a multi-random-access instance that writes to different instances of [random-access-memory](https://github.com/mafintosh/random-access-memory), each containing 10 bytes of data.

``` js
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:

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

Options include:

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

## License

MIT

---
_Source: https://npm.io/package/multi-random-access · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
