beakerbrowser / beaker

An experimental peer-to-peer Web browser
https://beakerbrowser.com/
MIT License
6.75k stars 544 forks source link

Block storage Web API (random-access-storage compliant) #1222

Open pfrazee opened 6 years ago

pfrazee commented 6 years ago

This has been a common request from people building database tools (eg @substack and @mafintosh).

The API should conform to random-access-storage. I think we can scope the data access to an origin (similar to localStorage) and provide multiple openable namespaces within that. The total data usage would be metered (maybe 100MB free with more space requestable?).

Pulling from random-access-storage we might do this API:

var storage = blockStorage(name)
storage.opened // bool
storage.closed // bool
storage.destroyed // bool
storage.addEventListener('open')
storage.addEventListener('close')
storage.addEventListener('destroy')
storage.open(cb)
storage.read(offset, size, callback)
storage.write(offset, buffer, [callback])
storage.del(offset, size, [callback])
storage.stat(callback)
storage.close([callback])
storage.destroy([callback])

We can't be 100% equivalent to random-access-storage because the event systems differ between node and the Web. I also removed the "readable/writable/deletable/statable" boolean flags but I would be fine having those in there (they'd all be true).

mafintosh commented 6 years ago

I don't think we use the events the hyper stack so this should* be compatible I think.

okdistribute commented 6 years ago

Yes, this would be nice so that we could easily upgrade/modify existing codebase running on electron to be beaker-compatible. There a few apps I have in mind on my to-build list coming up early next year for this..