dat-replication-protocol
Streaming implementation of the dat replication protocol
npm install dat-replication-protocol

Usage
var protocol = require('dat-replication-protocol')
var p = protocol(function(type, stream) {
if (type === protocol.CHANGES) {
stream.on('data', function(change) {
console.log('change:', change)
})
}
if (type === protocol.BLOB) {
stream.pipe(process.stdout)
}
})
var changes = p.createChangesStream()
changes.write({
key: 'some-row-key',
change: 0,
from: 0,
to: 1,
value: new Buffer('some binary value')
})
var blob = p.createBlobStream(12)
blob.write('hello ')
blob.write('world\n')
blob.end()
p.pipe(p)
This works similarly to the multiplex module except
this uses length prefixed streams for the blobs streams
Wire format
Basically all changes and blobs are sent as multibuffers (varint prefixed).
--------------------------------------------------
| varint length | single byte id | payload |
--------------------------------------------------
Since blobs can be large they are treated as streams.
License
MIT