hyperdb-plug-socket
v1.0.3
Published
Transform incoming and outgoing data from hyperdb
Downloads
3
Readme
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