Published
Edited
May 5, 2021
Insert cell
md`# [car file support](https://github.com/ipfs/ipfs-cluster/pull/1343/files) in IPFS cluster


`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ENDPOINT = 'http://127.0.0.1:9094'
Insert cell
Insert cell
cluster.add(new File(['foo 2'], 'hello.txt'))
Insert cell
cluster.addDirectory([new File(['hello world'], 'hello.txt', {type: "text/plain"})])
Insert cell
Insert cell
asset = importAsset(new File(['hello wrold'], 'hello.txt', {type: "text/plain"}))
Insert cell
Insert cell
inner = CBOR.encode({ hello: 'world' })
Insert cell
innerCID = CID.createV1(CBOR.code, await sha256.digest(inner))
Insert cell
innerCID.toString()
Insert cell
outer = CBOR.encode({ message: innerCID })
Insert cell
outerCID = CID.createV1(CBOR.code, await sha256.digest(outer))
Insert cell
outerCID.toString()
Insert cell
car = {
const { writer, out } = await CarWriter.create([outerCID])
writer.put({ cid: innerCID, bytes: inner })

writer.put({ cid :outerCID, bytes: outer })
writer.close()

const chunks = []

for await (const chunk of out) {

chunks.push(chunk)
}
return new Blob(chunks, { type: "application/car" })
}
Insert cell
cluster.add(car)
Insert cell
inner.byteLength + outer.byteLength
Insert cell
cluster.status('bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae')
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