Intro
Installable via npm install --save ipfs-block-service
, it can also be used directly in the browser.
Download
The source is available for download from GitHub. Alternatively, you can install using npm:
$ npm install --save ipfs-block-service
You can then require()
ipfs-block-service as normal:
const ipfsBlockService = require('ipfs-block-service')
In the Browser
Ipfs-block-service should work in any ES2015 environment out of the box.
Usage:
<script type="text/javascript" src="index.js"></script>
The portable versions of ipfs-block-service, including index.js
and index.min.js
, are included in the /dist
folder. Ipfs-block-service can also be found on unpkg.com under
BlockService
BlockService is a hybrid block datastore. It stores data in a local
datastore and may retrieve data from a remote Exchange.
It uses an internal datastore.Datastore
instance to store values.
Parameters
ipfsRepo: IPFSRepo
:
instance
BlockService.prototype.setExchange
setExchange(bitswap: Bitswap): void
Add a bitswap instance that communicates with the network to retreive blocks that are not in the local store.
If the node is online all requests for blocks first check locally and afterwards ask the network for the blocks.
Parameters
bitswap: Bitswap
:
Returns
void
BlockService.prototype.unsetExchange
unsetExchange(): void
Go offline, i.e. drop the reference to bitswap.
Returns
void
BlockService.prototype.hasExchange
hasExchange(): bool
Is the blockservice online, i.e. is bitswap present.
Returns
bool
BlockService.prototype.put
put(block: Block, callback: function (Error)): void
Put a block to the underlying datastore.
Parameters
block: Block
:callback: function (Error)
:
Returns
void
BlockService.prototype.putMany
putMany(blocks: Array<Block>, callback: function (Error)): void
Put a multiple blocks to the underlying datastore.
Returns
void
BlockService.prototype.get
get(cid: CID, callback: function (Error, Block)): void
Get a block by cid.
Parameters
cid: CID
:callback: function (Error, Block)
:
Returns
void