⛔️ DEPRECATED: This module has been merged into ipfs
IPFS Block Service
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.
constBlockService=require('ipfs-block-service')constBlock=require('ipld-block')constmultihashing=require('multihashing-async')constIPFSRepo=require('ipfs-repo')// storage repoconstuint8ArrayEquals=require('uint8arrays/equals')constuint8ArrayFromString=require('uint8arrays/from-string')// setup a repoconstrepo=newIPFSRepo('example')// create a blockconstdata=uint8ArrayFromString('hello world')constmultihash=awaitmultihashing(data,'sha2-256')constcid=newCID(multihash)constblock=newBlock(data,cid)// create a serviceconstservice=newBlockService(repo)// add the block, then retrieve itawaitservice.put(block)constresult=awaitservice.get(cid)console.log(uint8ArrayEquals(block.data,result.data))// => true
Browser: Browserify, Webpack, other bundlers
varBlockService=require('ipfs-block-service')
Browser: <script> Tag
Loading this module through a script tag will make the IpfsBlockService obj available in
the global namespace.
<scriptsrc="https://unpkg.com/ipfs-block-service/dist/index.min.js"></script><!-- OR --><scriptsrc="https://unpkg.com/ipfs-block-service/dist/index.js"></script>
请发表评论