-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
35 lines (26 loc) · 882 Bytes
/
example.js
File metadata and controls
35 lines (26 loc) · 882 Bytes
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
33
34
35
const dht = require('@hyperswarm/dht')
const ImmutableRecord = require('./')
if (process.argv[2] === 'put') {
put()
} else if (process.argv[2] === 'get-and-put') {
getAndPut()
} else {
get()
}
async function put () {
const record = ImmutableRecord.put(dht(), Buffer.from('ImmutableRecord example...'))
record.on('announced', function () {
console.log(record.key.toString('hex'), 'is announced')
})
// will keep announcing...
await record.announce()
}
async function get () {
const record = ImmutableRecord.get(dht(), '6d6fa568a45cba0865ad68b33f8e9dcd189fd88b39e78b6617207bcb91a9697d')
console.log((await record.get()).toString())
}
async function getAndPut () {
const record = ImmutableRecord.get(dht(), '6d6fa568a45cba0865ad68b33f8e9dcd189fd88b39e78b6617207bcb91a9697d')
console.log((await record.get()).toString())
await record.announce()
}