distributed-drive
v0.1.1
Published
Drive-compatible unified view across multiple peers and drives over RPC
Readme
distributed-drive
A drive-compatible unified view across multiple peers and drives over RPC. Connect your devices, register drives, and browse everything as one folder.
Note: This module was AI-generated with Claude and may need adjustments. Review before use in production.
Usage
const Hyperswarm = require('hyperswarm')
const Localdrive = require('localdrive')
const DistributedDrive = require('distributed-drive')
const drive = new DistributedDrive(new Localdrive('./movies'), new Localdrive('./music'))
const swarm = new Hyperswarm()
swarm.join(topic)
swarm.on('connection', (stream) => drive.addPeer(stream))
// unified view — local + remote files merged
for await (const entry of drive.list('/')) {
console.log(entry.key)
}
const buf = await drive.get('/photos/beach.jpg')Try it
On machine A:
node run.jsOn machine B (using the key printed by A):
node run.js <key>Share a specific directory:
node run.js -p ~/movies
node run.js <key> -p ~/photosREPL commands
ls [path] list files
cat <path> print file contents
cp <path> [dest] copy remote file locally
find <query> search filenames
peers show connected peers
exit quitAPI
new DistributedDrive(...drives, [opts]) — create a drive, optionally registering drives upfront.
drive.register(drive) / drive.unregister(drive) — add or remove a local drive.
drive.addPeer(stream) — add an encrypted stream from Hyperswarm. Opens a protomux-rpc channel. Peer is removed automatically on stream close.
await drive.entry(path) — get entry metadata. Checks local drives, then cache, then fans out to peers.
await drive.get(path) — get file contents as a buffer. Same lookup order.
drive.list(prefix) — readable stream of entries merged from all drives and peers, deduplicated by key.
drive.createReadStream(path) — readable stream of file contents.
How it works
Each peer connection is symmetric — both sides share their registered drives and can query the other's. There is no client/server distinction. Metadata is cached lazily with record-cache and disconnected peers are filtered on read. The RPC protocol uses hyperschema for encoding and protomux-rpc for transport.
Security is handled below this module — Hyperswarm connections are encrypted via secret-stream. The swarm topic acts as the shared secret.
License
Apache-2.0
