UNPKG

515 BJavaScriptView Raw
1const raf = require('random-access-file')
2const Corestore = require('corestore')
3
4module.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
14function isCorestore (storage) {
15 return storage.default && storage.get && storage.replicate && storage.close
16}