Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

@sammacbeth/dat-archive-web

1.1.2 • Public • Published

dat-archive-web

DatArchive implementation for browsers that uses dat-gateway

Uses a fork of dat-gateway that supports synchronization over websockets.

Based on node-dat-archive

Public gateway: gateway.mauve.moe:3000

npm install --save dat-archive-web

Example

// After including the bundle in a script tag, or requiring it
 
const archive = new DatArchive('dat://87ed2e3b160f261a032af03921a3bd09227d0a4cde73466c17114816cae43336')
 
archive.readFile('/index.html')
  .then((html) => console.log(html))

API

Implements the same interface as DatArchive in Beaker with the following exceptions:

  • archive.diff(), archive.commit(), and archive.revert() are not supported
  • DatArchive.selectArchive() returns a new DatArchive every time (You can implement better behavior in the Manager)
  • By default requires an instance of dat-gateway running on http://localhost:3000
  • Uses DatArchive.setManager() to set the manager which is an object with the following API:
    • getStorage(key: String) : Promise<Storage> : Retruns the storage to use with hyperdrive. By default it will persist to memory
    • selectArchive(options) : Promise<String> : Returns the URL of a user selected archive. Takes same options as the DatArchive API. By default it returns null to always create a new archive
    • replicate(key: String) : Stream : Returns a stream used to replicate the hyperdrive instance. By default it will connect to the gateway over websockets.
    • resolveName(url: String) : Promise<String> resolves a dat URL with a hostname to a dat URL which uses the public key
    • onAddArchive(key: String, secretKey: String, options: Object) : Promise<void> invoked whenever DatArchive.create() is invoked. Allows managers to save the dat information to be used in selectArchive()
    • An implementation can be found in DefaultManager that can be extended to do fancier things.
    • Can also be used by extending from DatArchive.DefaultManager

Setting a custom gateway

const DatArchive = require('dat-archive-web')
const DefaultManager = DatArchive.DefaultManager
 
// Use a public dat gateway so you don't need a local one
const publicGateway = 'gateway.mauve.moe:3000'
DatArchive.setManager(new DefaultManager(publicGateway))

Features

  • Support most DatArchvie methods
  • Public gateway at http://gateway.mauve.moe:3000/
  • Extensiblity for different environments
  • Detect HTTP/HTTPS in gateway URL
  • Functional DatDNS support (via gateway)
  • Data stored in memory by default
  • Can persist to IndexedDB (via random-access-idb)
  • Full support for versions (Needs testing, but code is there)
  • Forking (without preserving change feed)
  • DatArchive.selectArchive() (function offloaded to Manager)

Development

  • This project uses the standard code style
  • Run the example in node with npm install && npm run example
  • Build the browserify bundle with npm run build

Install

npm i @sammacbeth/dat-archive-web

DownloadsWeekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

20.9 kB

Total Files

9

Last publish

Collaborators

  • avatar