1.3.5 • Published 5 years ago

universal-dat-storage v1.3.5

Weekly downloads
18
License
MIT
Repository
github
Last release
5 years ago

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

API

const Storage = require('universal-dat-storage')

const storage = new 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.decode(`dat://0a9e202b8055721bd2bc93b3c9bbc03efdbda9cfee91f01a123fdeaadeba303e`)

// Get storage specific to hyperdrive (for the metadata and content feed)
const drive = hyperdrive(storage.getDrive(key))

// Get storage for a given folder
const drive = hyperdrive(storage.getDrive('/home/mauve/example'))

const drive = hyperdrive(storage.getDrive('./example'))

// Get storage for a specific hypercore key
const core = hypercore(storage.getCore(key))

// Get storage for a given corestore
const store = corestore(storage.getCoreStore(name))

// Get the location of the storage on disk
// Only works for valid keys, not file paths
const location = storage.getLocation(key)

// Delete the storage for a given hypercore or hyperdrive
// Only works for valid keys, not file paths
// Doesn't work on the web
storage.delete(key, () => {
  console.log('Done!')
})
1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago