Skip to content

create a hypercore stream that replicates across a swarm

Notifications You must be signed in to change notification settings

lukeburns/hypercore-stream-swarm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hypercore-stream-swarm

Create a hypercore stream from a public or private key that replicates across a hyperdrive-archive-swarm.

npm install hypercore-stream-swarm

Usage

var createStream = require('hypercore-stream-swarm')
var signatures = require('sodium-signatures')

var keys = signatures.keyPair()
var publisher = createStream(keys.secretKey)
var consumer = createStream(keys.publicKey)
publisher.write('hello')
consumer.once('data', function (block) {
  console.log(block) // hello
})

API

var stream = createStream([key], [options])

Same as hypercore-stream with an additional close option, which closes the swarm when the stream ends.

key is either a public or private key. If it is a public key, then the stream will be readable only. If it is a private key, then the stream will be both readable and writable. If it is undefined, then a new feed is created with public and private keys stream.key and stream.secretKey.

All options are optional.

{
  db: leveldb instance,
  static: boolean,
  storage: object,
  tail: boolean,
  start: integer,
  end: integer,
  close: boolean
}

stream.swarm

The hyperdrive swarm instance.

stream.close(callback)

Leave swarm.

stream.on('close')

Event emitted upon closing the swarm.

stream.on('connection', connection, info)

Emitted when you connect to another peer. Info is an object that contains info about the connection

{
  type: 'tcp', // the type, tcp or utp
  initiator: true, // wheather we initiated the connection or someone else did
  channel: Buffer('...'), // the channel this connetion was initiated on. only set if initiator === true
  host: '127.0.0.1', // the remote address of the peer.
  port: 8080, // the remote port of the peer.
  id: Buffer('...') // the remote peer's peer-id.
}

About

create a hypercore stream that replicates across a swarm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages