From 4d42ff055bb44d55a4c713b9065222e10fce3ee6 Mon Sep 17 00:00:00 2001 From: Alexander Praetorius Date: Fri, 16 Aug 2019 17:45:33 +0100 Subject: [PATCH 1/2] Add option to provide custom random-access storage --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2ef60a0..01e3dda 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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) From cbb2cdef7cbbbeb5ec5b7645c9e5cbb5e6ce2f82 Mon Sep 17 00:00:00 2001 From: Alexander Praetorius Date: Fri, 16 Aug 2019 17:49:18 +0100 Subject: [PATCH 2/2] Update readme API example with opts.storage --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1007b0..d970501 100644 --- a/README.md +++ b/README.md @@ -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(() => {