IPFS Block Service JavaScript Implementation
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│
└─────────┘ └───────┘
Table of Contents
Install
npm
> npm install ipfs-block-service
Usage
Node.js
const BlockService = require('ipfs-block-service')
Example
const BlockService = require('ipfs-block-service')
const Block = require('ipfs-block')
const IPFSRepo = require('ipfs-repo')
const repo = new IPFSRepo('example')
const data = new Buffer('hello world')
multihashing(data, 'sha2-256', (err, multihash) => {
if (err) {
throw err
}
const cid = new CID(multihash)
const block = new Block(data, cid)
const bs = new BlockService(repo)
bs.put(block, (err) => {
if (err) {
throw err
}
bs.get(cid, (err, b) => {
if (err) {
throw err
}
console.log(block.data.toString() === b.data.toString())
})
})
})
Browser: Browserify, Webpack, other bundlers
var BlockService = require('ipfs-block-service')
Browser: <script>
Tag
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>
<script src="https://unpkg.com/ipfs-block-service/dist/index.js"></script>
API
See https://ipfs.github.io/js-ipfs-block-service
Contribute
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
License
MIT