ipfs-block-service
0.15.2

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

  1. 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

  1. 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

  1. block: Block:  
  2. callback: function (Error):  

Returns

void

BlockService.prototype.putMany

putMany(blocks: Array<Block>, callback: function (Error)): void

Put a multiple blocks to the underlying datastore.

Parameters

  1. blocks: Array<Block>:  
  2. callback: function (Error):  

Returns

void

BlockService.prototype.get

get(cid: CID, callback: function (Error, Block)): void

Get a block by cid.

Parameters

  1. cid: CID:  
  2. callback: function (Error, Block):  

Returns

void

BlockService.prototype.getMany

getMany(cids: Array<CID>, callback: function (Error, Block)): void

Get multiple blocks back from an array of cids.

Parameters

  1. cids: Array<CID>:  
  2. callback: function (Error, Block):  

Returns

void

BlockService.prototype.delete

delete(cid: CID, callback: function (Error)): void

Delete a block from the blockstore.

Parameters

  1. cid: CID:  
  2. callback: function (Error):  

Returns

void