Browse Source

add binary for mounting a normal hyperdrive to test/

ameba23 3 years ago
parent
commit
a670ecaa3e
1 changed files with 32 additions and 0 deletions
  1. 32
    0
      test/mount_hyperdrive.js

+ 32
- 0
test/mount_hyperdrive.js View File

@@ -0,0 +1,32 @@
1
+#!/usr/bin/env node
2
+// This script is to mount a normal hyperdrive in the same way we would
3
+// mount a kappa-drive, to make it easy to compare thier behaviour.
4
+// Ideally we want to make all filesystem operations which are possible with
5
+// hyperdrive also possible with kappa-drive
6
+const minimist = require('minimist')
7
+const ram = require('random-access-memory')
8
+const path = require('path')
9
+
10
+const mount = require('..')
11
+const hyperdrive = require('hyperdrive')
12
+
13
+const STORAGE = (p) => path.resolve(p)
14
+
15
+const argv = minimist(process.argv.slice(2))
16
+var storage
17
+
18
+if (argv.db) {
19
+  storage = argv.db ? STORAGE(argv.db) : ram
20
+} else {
21
+  storage = ram
22
+}
23
+
24
+var mountdir = argv.mount || './mnt'
25
+var key = argv.key ? Buffer.from(argv.key, 'hex') : null
26
+
27
+var drive = hyperdrive(storage, key)
28
+
29
+drive.ready(() => {
30
+  mount(drive, mountdir)
31
+  // swarm(drive)
32
+})