Skip to content

Commit

Permalink
Fixed up storage
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerMauve committed Aug 19, 2019
1 parent 5883050 commit ece7fce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')

// This is a dirty hack for browserify to work. 😅
if(!path.posix) path.posix = path
if (!path.posix) path.posix = path

const discovery = require('hyperdiscovery')
const datStorage = require('universal-dat-storage')
Expand Down Expand Up @@ -93,7 +93,13 @@ function SDK ({ storageOpts, swarmOpts, driveOpts, coreOpts, dnsOpts } = {}) {

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

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

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

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

0 comments on commit ece7fce

Please sign in to comment.