Public
Edited
Jul 31, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ipfsNode = await ipfs.create()
Insert cell
{
for await (const treeData of onTreeIterator()) {
await Promises.delay(100)
const dataCids = []
for (let i = 0; i < feed.length; i++) {
const options = { format: 'raw', hashAlg: 'blake2b-256' }
const data = await feedGet(feed, i)
const leaf = Buffer.concat([
Buffer.from([0]),
uint64be.encode(data.length),
data
])
const cid = await ipfsNode.dag.put(leaf, options)
dataCids.push(cid.toString())
}
yield dataCids
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
storageShim = shimAndIterators.storageShim
Insert cell
Insert cell
Insert cell
feed = hypercore(storageShim)
Insert cell
{
await Promises.delay(1000)
appendRandomFruit(feed);
return "init with random fruit"
}
Insert cell
function appendButton () {
const div = html`
<div>
<button>Append a record to the feed</button>
<span></span>
<div>
`
const button = div.querySelector('button')
const span = div.querySelector('span')
button.onclick = () => {
const fruit = appendRandomFruit(feed)
span.innerText = `Appended: ${fruit}`
}
return div
}
Insert cell
ipfs = require('ipfs@0.48.1/dist/index.min.js')
Insert cell
buf = require('https://bundle.run/buffer@5.6.0')
Insert cell
Buffer = buf.Buffer

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more