Skip to content

Instantly share code, notes, and snippets.

@hackergrrl
Last active October 30, 2019 20:41
Show Gist options
  • Save hackergrrl/518ca15fdf70791940b23658bad2f162 to your computer and use it in GitHub Desktop.
Save hackergrrl/518ca15fdf70791940b23658bad2f162 to your computer and use it in GitHub Desktop.
corestorage api
let store = corestore('my-storage-dir' || ram() || webstore())
// Map a discovery key or local-name to a key.
store.keyFromDiscoveryKey(discoKey, cb)
store.keyFromLocalName('my-feed', cb)
// Create a new hypercore, which can include a local name. (creates + loads)
let core = store.create('localname', { valueEncoding: 'utf-8' })
core.ready(cb)
// Get an existing hypercore by key or local name. Local names are purely local & aren't shared over the network.
// Loads the core if it isn't loaded.
store.get(id, cb)
// Returns boolean true/false if core is loaded from disk.
store.isLoaded(id, cb)
// Unload a hypercore.
store.close(id, cb)
// Close all hypercores.
store.closeAll(cb)
// Unload and delete a hypercore.
store.delete(id, cb)
@telamon
Copy link

telamon commented Oct 19, 2019

Wow Nice! quick feedback:
Is it possible to drop the ready() pattern? My gut is trying to tell me something that it's gonna be problematic to define "ready"-state when we start working with sparse-loaded cores. an async store.list() would maybe fullfill the same functionality?

I haven't paid enough attention yet so i'm not sure if the following comment is relevant:
I'm little bit curious if it's possible to slim down kappa-core and deprecate kappa#writer(name, cb) , kappa#feed(key) and kappa#feeds() methods. Been exprimenting with the thought of letting kappa only handle indexing regardless of which source it's feeds are from.. Having said that, i haven't yet thought of how to alternatively provide feeds to kappa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment