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. |
Classes
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. |
# 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. |
# 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. |
# online()
online returns whether the block service is online or not. i.e. does it have a valid exchange?
# async put(block)
put adds a block to the underlying block store.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | An immutable block of data. |