Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mafintosh/multi-random-access
An abstract-random-access compliant instance that combines multiple other abstract-random-access instances into a single one.
https://github.com/mafintosh/multi-random-access
Last synced: about 1 month ago
JSON representation
An abstract-random-access compliant instance that combines multiple other abstract-random-access instances into a single one.
- Host: GitHub
- URL: https://github.com/mafintosh/multi-random-access
- Owner: mafintosh
- License: mit
- Created: 2016-08-01T16:44:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-25T01:10:14.000Z (about 5 years ago)
- Last Synced: 2024-12-17T15:47:24.492Z (about 1 month ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 15
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dat - multi-random-access - combine multiple `abstract-random-access` stores into a single one (Dat Core Modules / Storage)
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