Skip to content

Commit

Permalink
Merge pull request #19 from ninabreznik/master
Browse files Browse the repository at this point in the history
Add option to provide custom random-access storage and update Readme
  • Loading branch information
RangerMauve authored Oct 7, 2019
2 parents 2128b0a + cf86d91 commit 7c7b6bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ const archive = Hyperdrive(null, {
// This is here so that running the example doesn't clog up your history
persist: false,
// storage can be set to an instance of `random-access-*`
// const RAI = require('random-access-idb')
// otherwise it defaults to `random-access-web` in the browser
// and `random-access-file` in node
storage: null
storage: null //storage: RAI
})

archive.ready(() => {
Expand Down Expand Up @@ -113,7 +114,12 @@ function reallyReady (archive, cb) {
// https://github.com/mafintosh/hypercore
const myCore = Hypercore(null, {
valueEncoding: 'json',
persist: false
persist: false,
// storage can be set to an instance of `random-access-*`
// const RAI = require('random-access-idb')
// otherwise it defaults to `random-access-web` in the browser
// and `random-access-file` in node
storage: null // storage: RAI
})

// Add some data to it
Expand Down
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,18 @@ function SDK ({ storageOpts, swarmOpts, driveOpts, coreOpts, dnsOpts } = {}) {
if (cores.has(stringKey)) return cores.get(stringKey)

const { persist } = opts

const coreStorage = persist ? storage.getCore(location) : RAM
let coreStorage = null
try {
if (!persist) {
coreStorage = RAM
} else if (opts.storage) {
coreStorage = opts.storage(location)
} else {
coreStorage = storage.getCore(location)
}
} catch (e) {
if (e.message !== 'Unable to create storage') throw e
}

const core = hypercore(coreStorage, key, opts)

Expand Down

0 comments on commit 7c7b6bf

Please sign in to comment.