⛔️ DEPRECATED: This module has been merged into ipfs
IPFS implementation of the BlockService and Block data structure in JavaScript.
BlockService - A BlockService is a content-addressable store for blocks, providing an API for adding, deleting, and retrieving blocks. A BlockService is backed by an IPFS Repo as its datastore for blocks, and uses Bitswap to fetch blocks from the network.
┌───────────────────┐
│ BlockService │
└───────────────────┘
┌─────┴─────┐
▼ ▼
┌─────────┐ ┌───────┐
│IPFS Repo│ |Bitswap│
└─────────┘ └───────┘
> npm install ipfs-block-service
const BlockService = require('ipfs-block-service')
const BlockService = require('ipfs-block-service')
const Block = require('ipld-block')
const multihashing = require('multihashing-async')
const IPFSRepo = require('ipfs-repo') // storage repo
const uint8ArrayEquals = require('uint8arrays/equals')
const uint8ArrayFromString = require('uint8arrays/from-string')
// setup a repo
const repo = new IPFSRepo('example')
// create a block
const data = uint8ArrayFromString('hello world')
const multihash = await multihashing(data, 'sha2-256')
const cid = new CID(multihash)
const block = new Block(data, cid)
// create a service
const service = new BlockService(repo)
// add the block, then retrieve it
await service.put(block)
const result = await service.get(cid)
console.log(uint8ArrayEquals(block.data, result.data))
// => true
var BlockService = require('ipfs-block-service')
Loading this module through a script tag will make the IpfsBlockService
obj available in
the global namespace.
<script src="https://unpkg.com/ipfs-block-service/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipfs-block-service/dist/index.js"></script>
See https://ipfs.github.io/js-ipfs-block-service
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.