1 | const raf = require('random-access-file')
|
2 | const Corestore = require('corestore')
|
3 |
|
4 | module.exports = function defaultCorestore (storage, opts) {
|
5 | if (isCorestore(storage)) return storage
|
6 | if (typeof storage === 'function') {
|
7 | var factory = path => storage(path)
|
8 | } else if (typeof storage === 'string') {
|
9 | factory = path => raf(storage + '/' + path)
|
10 | }
|
11 | return new Corestore(factory, opts)
|
12 | }
|
13 |
|
14 | function isCorestore (storage) {
|
15 | return storage.default && storage.get && storage.replicate && storage.close
|
16 | }
|