Class

BlockService

BlockService(store, exchange)

BlockService is a content-addressable store for adding, deleting, and retrieving blocks of immutable data. A block service is backed by a block store as its datastore for blocks, and uses an "exchange" (bitswap) to fetch blocks from the network. This implementation is a simplified variant of the official IPFS block service, requiring only a simple block store (not a full IPFS repo), and reference to a bitwap exchange. It satisfies the default IPFS block service interface: https://github.com/ipfs/js-ipfs-block-service.

Constructor

# new BlockService(store, exchange)

BlockService creates a new block service.
Parameters:
Name Type Description
store BlockStore The block store to use for local block storage.
exchange Bitswap Add a "bitswap" instance that communicates with the network to retrieve blocks that are not in the local store. If the node is online, all requests for blocks first check locally and then ask the network for the blocks. To 'go offline', simply set `exchange` to undefined or null.

View Source core/blockservice.ts, line 19

Classes

BlockService

Methods

# async delete(cid)

delete removes a block from the local block store.
Parameters:
Name Type Description
cid CID The content identifier for an immutable block of data.

View Source core/blockservice.ts, line 91

# async get(cid)

get returns a block by its content identifier. If the block is not available locally and the exchange is online, it will request the block from the network.
Parameters:
Name Type Description
cid CID The content identifier for an immutable block of data.

View Source core/blockservice.ts, line 61

# async generator getMany(cids)

getMany returns multiple blocks from an iterable of content identifiers. If any of the blocks are not available locally and the exchange is online, it will request the block(s) from the exchange/network.
Parameters:
Name Type Description
cids Iterable.<CID> Iterable of content identifiers for immutable blocks of data.

View Source core/blockservice.ts, line 76

# online()

online returns whether the block service is online or not. i.e. does it have a valid exchange?

View Source core/blockservice.ts, line 26

# async put(block)

put adds a block to the underlying block store.
Parameters:
Name Type Description
block Block An immutable block of data.

View Source core/blockservice.ts, line 34

# async putMany(blocks)

putMany adds multiple blocks to the underlying block store.
Parameters:
Name Type Description
blocks Iterable.<Block> An iterable of immutable blocks of data.

View Source core/blockservice.ts, line 47