A pure JavaScript browser-friendly api for using dat.
This repo is not actively maintined. It uses WebRTC for the networking, which none of our other tools use. See this issue for more details and discussion.
Dat is a powerful decentralized data sharing tool. For a Node.js api for working with dats on the filesystem, see dat-node.
Note: Because dat-js uses webrtc, it can only connect to other browser clients. It is not possible for the dat-js library to connect to the UTP and UDP clients used in the Node.js versions.
Want to use Dat in the command line or an app (not build applications)? Check out:
- Dat CLI: Use Dat in the command line
- Dat-Desktop: A desktop application for Dat
Learn more! docs.datproject.org or chat with us (#dat on IRC)
var Dat = require('dat-js')
var concat = require('concat-stream')
var dat = Dat()
dat.add('ARCHIVE_KEY', function (repo) {
var readStream = repo.archive.createFileReadStream('hello.txt')
concat(readStream, function (data) {
console.log(data)
})
})
var Dat = require('dat-js')
var dat = Dat()
dat.add(function (repo) {
console.log('dat key is:', repo.key)
var writer = repo.archive.createFileWriteStream('hello.txt')
writer.write('world')
writer.end(function () { replicate(repo.key) })
})
function replicate (key) {
var clone = Dat()
clone.add(key, function (repo) {
var readStream = repo.archive.createFileReadStream('hello.txt')
readStream.on('data', function (data) {
console.log(data.toString()) // prints 'world'
})
})
}
Creates a new dat object. The options passed here will be default for any dats created using the add
method.
options
: any options you can pass to mafintosh/hyperdrive. These options will become default for all dats.
Adds a new dat with the given key. Joins the appropriate swarm for that key and begins to upload and download data. The onrepo
function will be called when the dat is finished being created.
options
: These options will override any options given in the Dat constructor.
Array of repo instances
The repo object managed by dat.
The key of the repo
Destroys the swarm and underlying database.
Get to the original webrtc-swarm
instance, where the swarm can be managed.
Get to the original hyperdrive
archive instance, where files can be managed using that api.
Fired every time a new repo is ready.
Fired when dat is finished closing, including swarm and database.