hyperdb-plug-socket

1.0.3 • Public • Published

hyperdb-plug-socket

Transform incoming and outgoing data from hyperdb

usage

This is a simple library for applying a transformation to incoming and outgoing data inside a hyperdb. Currently get, put and createReadStream are implemented.

var hyperdb = require('hyperdb')
var plugsocket = require('hyperdb-plug-socket')
var db = plugsocket(hyperdb(ram, { valueEncoding: 'json' }))

db.encoder = function (a) {
  return a
}

db.decoder = function (a) {
  a[0].value.a = 'intercepted!'
  return a
}

db._put('/demo', { a: Math.random () }, function () {
  db._get('/demo', function (e, d) {
    var d = db._createReadStream('/demo')
    d.on('data', function (d) {
      assert.ok(typeof d === 'object')
      assert.ok(d[0].value.a === 'intercepted!')
      console.log('test passes!')
    })
  })
})

Provide an encoder and decoder function, this will be applied to function calls that use the underscore...

db._get() // uses the  function
db.get() // does NOT use the decoder function

db._put() // uses the encoder function
db.put() // does NOT use the encoder function

install

npm i hyperdb-plug-socket

Readme

Keywords

none

Package Sidebar

Install

npm i hyperdb-plug-socket

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

3.32 kB

Total Files

4

Last publish

Collaborators

  • m-onz