-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.js
32 lines (23 loc) · 897 Bytes
/
backend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { Client } = require('hyperspace')
const DTree = require('hyperbee')
const { kvPairs : dictionaryPairs } = require('websters-english-dictionary')
start()
async function start() {
const { corestore, replicate } = new Client()
const store = corestore()
// create storage for the dTree we're going to use to store the dictionary
const core = store.get({ name: 'dictionary' })
// create dTree
const db = new DTree(core, { keyEncoding: 'utf-8', valueEncoding: 'utf-8' })
//await db.ready()
// store each definition in the dictionary as key/value pairs using dTree's batch method
const batch = db.batch()
for (const { key, value } of dictionaryPairs()) {
await batch.put(key, value)
}
await batch.flush()
// Print dTree key
console.log(' bee ', db.feed.key.toString('hex'))
// Now announce on dWeb
await replicate(core)
}