Skip to content

JamesKyburz/level-range-emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

level-range-emitter

range emitter hooks for leveldb

client and server using multileveldown, range-emitter and ltgt

js-standard-style Greenkeeper badge downloads

client example

const websocket = require('websocket-stream')
const multileveldown = require('multileveldown')
const rangeEmitter = require('level-range-emitter').client
const db = multileveldown.client({ keyEncoding: 'utf8', valueEnoding: 'json', retry: true })
const re = rangeEmitter(db)
;(function connect () {
  const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'
  const url = `${protocol}://${window.location.host}/db`
  const ws = websocket(url)
  const remote = db.connect()
  re.session(remote, ws)
  ws.on('close', window.setTimeout.bind(window, connect, 3000))
})()

re.subscribe((key, type) => console.log('changed %s', key, type))

server example

  const lre = require('level-range-emitter').server(db)
  const session = lre.session
  const dbStream = multileveldown.server(dbInstance)
  session(dbStream, stream)