Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RAM.reusable() as default storage to support reopening cores #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading