🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

dat-http-replicator

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dat-http-replicator

push/pull a dat repo over a HTTP REST API

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
3
Created
Source

dat-http-replicator

npm install dat-http-replicator

build status

Usage

On a server

var replicator = require('dat-http-replicator')
var http = require('http')

var server = http.createServer(function (req, res) {
  var progress = replicator.server(datGraphInstance, req, res)
  if (!progress) return

  progress.on('pull', function () {
    console.log('server pulled', progress.pulled)
  })

  progress.on('push', function () {
    console.log('server pushed', progress.pushed)
  })
})

server.listen(9000)

On a client

var replicator = require('dat-http-replicator')
var progress = replicator(datGraphInstance, 'http://localhost:9000')

progress.on('pull', function () {
  console.log('client pulled', progress.pulled)
})

progress.on('push', function () {
  console.log('client pushed', progress.pushed)
})

progress.on('end', function () {
  console.log('done replicating')
})

progress.on('error', function (err) {
  console.log('error!', err)
})

API

progress = replicator.server(datGraph, req, res, [opts], [cb])

Setup a server http handler. Options include:

{
  readonly: true, // do not allow pushes
  writeonly: true // do not allow pulls
}

Note that the progress monitor will be null if this is an endpoint without progress monitoring support.

progress = replicator.client(datGraph, url, [opts], [cb])

Make a replication request. Options include:

{
  mode: 'push' | 'pull' | 'sync' // defaults to sync
}

Progress monitoring

The progress monitor returned will emit push and pull when you send a graph node or receive a graph node. The progress events look like this

{
  transferred: nodesTransferredSoFar,
  length: totalNumberOfNodesToTransfer
}

The latest progress event call also be accessed at progress.pushed and progress.pulled

Keywords

dat

FAQs

Package last updated on 29 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts