universal-dat-storage
Handle storing Dats in crazy environments
Why?
Dealing with Storage in Dats is really fragmented. Beaker has it's own way of doing it, the Dat CLI has it's own way of doing it, random hypercore based projects have their own way of doing it, and all of that is incompatible with the web.
This module hopes to unify all these environments and have one place for all of Dat's storage needs.
Goals
- Support Hyperdrives and Hypercores
- Take dat keys (buffer or URL) or file paths
- Standard folder for hypercore metadata. Use env-paths data path
- Detect how to get the Dat for a file path
- Check for
.dat
folder, use dat-storage if it exists. - Check for
.dat
file, identifies key to look up metadata in the standard place - ~Create
.dat
file with a new key if nothing else exists~ This should be done at the application level. (in the SDK, for example)
- Check for
- ~Check in Beaker's storage~ (That's changing to be the daemon)
- ~Uses app.getPath(), with "userData", then "Dat", and "Archives" / "Meta" /
key.slice(0,2)
/key.toString('hex')
~
- ~Uses app.getPath(), with "userData", then "Dat", and "Archives" / "Meta" /
- Web support
API
const Storage = const storage = // Change the application name to use in the env-path module application: 'dat' // Only specify this if you really know what you're doing // Ideally data should be stored using env-paths to make operating systems happy storageLocation: null // Support relative paths for folders useRelativePaths: true // Whether we should search for keys in Beaker useBeaker: true // Whether we should use the legacy `.dat` folder feature useDatFolder: true // Whether we should use the new `.dat` file feature useDatFile: true const key = DatEncoding // Get storage specific to hyperdrive (for the metadata and content feed)const drive = // Get storage for a given folderconst drive = const drive = // Get storage for a specific hypercore keyconst core = // Get storage for a given corestoreconst store = // Get the location of the storage on disk// Only works for valid keys, not file pathsconst location = storage // Delete the storage for a given hypercore or hyperdrive// Only works for valid keys, not file paths// Doesn't work on the webstorage