present a bundle of hyperdrive archives together as a multi-writer view
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


present a bundle of hyperdrive archives together as a multi-writer view

This module create a writable archive on each database and creates readable archives for every other remote peer. The data from these archives are presented as a single view, even though there are many archives behind the scenes.


var multidrive = require('hyperdrive-multiwriter')
var hyperdrive = require('hyperdrive')
var level = require('level')
var sub = require('subleveldown')

var db = level(process.argv[2])
var mdrive = multidrive({
  db: db,
  drive: hyperdrive(sub(db,'d'))

if (process.argv[3] === 'list') {
  mdrive.list(function (err, entries) {
    entries.forEach(function (entry) {
} else if (process.argv[3] === 'read') {
  var entry = JSON.parse(process.argv[4])
} else if (process.argv[3] === 'write') {
} else if (process.argv[3] === 'sync') {
  var r = mdrive.replicate()

create some data:

$ echo HI | node drive.js /tmp/a write hello.txt
$ echo HOWDY | node drive.js /tmp/b write hello.txt
$ echo WHATEVER | node drive.js /tmp/c write cool.txt

gossip replication (npm install -g dupsh):

$ dupsh 'node drive.js /tmp/a sync' 'node drive.js /tmp/b sync'
$ dupsh 'node drive.js /tmp/b sync' 'node drive.js /tmp/c sync'
$ dupsh 'node drive.js /tmp/a sync' 'node drive.js /tmp/b sync'

now each node has all the data:

$ node drive.js /tmp/a list
$ node drive.js /tmp/a read '{"name":"cool.txt","link":"c34e0d868ae6371dff499733befe5213f9cf1573a4bb14eb4eb105f2a7408860"}'


var multidrive = require('hyperdrive-multiwriter')

var mdrive = multidrive(opts)

Create a multi-writer hyperdrive instance mdrive from opts:

  • opts.db - levelup database
  • - hyperdrive instance

mdrive has most of the same methods as a hyperdrive archive instance.

The rest of the opts are passed through to drive.createArchive(opts).

var r = mdrive.list(opts, cb)

Return a readable stream r with entries from all the archives or collect all the entries as cb(err, entries).

Each entry has an hex string added to it to associate it with the proper archive..

var w = mdrive.createFileWriteStream(entry)

Store data in the archive by writing to a writable stream w.

entry should be an object or a string interpreted as

var r = mdrive.createFileReadStream(entry)

Create a readable stream for the contents of entry.

entry should have an and

mdrive.append(entry, cb)

Append an entry into the writable archive.

mdrive.get(entry, opts, cb)

Read an entry from the archive as cb(err, entry)., opts, cb)

Fully download a file/entry from the archive.


Close all resources.

var cursor = mdrive.createByteCursor(entry)

Create a cursor that can seek and traverse entry.

var stream = mdrive.replicate()

Return a duplex stream for replication that multiplexes the replication streams of all the underlying archives along with a coordinator channel to create the required readable archives on both sides of the connection.


Stop replicating a stream. If stream isn't given, stops all replication stream on mdrive.


npm install hyperdrive-multiwriter