Skip to content

Commit

Permalink
Merge pull request #102 from lejeunerenard/change-default-ram-to-resu…
Browse files Browse the repository at this point in the history
…able

Use RAM.reusable() as default storage to support reopening cores
  • Loading branch information
RangerMauve authored Apr 8, 2024
2 parents f30bd08 + 5e33e21 commit 67d54f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export async function create ({
if (isStringStorage && !isPathStorage) {
storageBackend = RAA(storage)
} else if (storage === false) {
storageBackend = RAM
storageBackend = RAM.reusable()
}

const corestore = opts.corestore || new CoreStore(storageBackend, { ...corestoreOpts })
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"hyperdrive": "^11.8.1",
"hyperswarm": "^4.7.14",
"random-access-application": "^2.0.0",
"random-access-memory": "^6.1.0",
"random-access-memory": "^6.2.0",
"z32": "^1.0.1"
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ test('Specify storage for sdk', async (t) => {
}, { unsafeCleanup: true })
})

test('Support storage reuse by default', async (t) => {
const sdk = await create({ storage: false })
const core = await sdk.get('persist in memory')
const key = core.key

const data = b4a.from('beep')
await core.append(data)
await core.close()
t.ok(core.closed, 'initial core was closed')

const coreAgain = await sdk.get(key)
t.deepEqual(await coreAgain.get(0, { wait: false }), data, 'found persisted data')

await sdk.close()
})

test('Load hypercores by names and urls', async (t) => {
const sdk = await create({ storage: false })
const name = 'example'
Expand Down

0 comments on commit 67d54f7

Please sign in to comment.