Skip to content

Commit

Permalink
Merge pull request #13 from serapath-contribution/master
Browse files Browse the repository at this point in the history
add `opts.storage` option to change which `random-access-*` module is used
  • Loading branch information
RangerMauve authored Aug 16, 2019
2 parents 62b624c + cbb2cde commit dac2317
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ const { Hypercore, Hyperdrive, resolveName, deleteStorage, destroy } = SDK()
const archive = Hyperdrive(null, {
// This archive will disappear after the process exits
// This is here so that running the example doesn't clog up your history
persist: false
persist: false,
// storage can be set to an instance of `random-access-*`
// otherwise it defaults to `random-access-web` in the browser
// and `random-access-file` in node
storage: null
})

archive.ready(() => {
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function SDK ({ storageOpts, swarmOpts, driveOpts, coreOpts, dnsOpts } = {}) {

let driveStorage = null
try {
driveStorage = persist ? storage.getDrive(location) : RAM
driveStorage = persist ? opts.storage || storage.getDrive(location) : RAM
} catch (e) {
if (e.message !== 'Unable to create storage') throw e

Expand All @@ -104,7 +104,7 @@ function SDK ({ storageOpts, swarmOpts, driveOpts, coreOpts, dnsOpts } = {}) {
location = DatEncoding.encode(publicKey)
opts.secretKey = secretKey

driveStorage = persist ? storage.getDrive(location) : RAM
driveStorage = persist ? opts.storage || storage.getDrive(location) : RAM
}

const drive = hyperdrive(driveStorage, key, opts)
Expand Down

0 comments on commit dac2317

Please sign in to comment.