npm install --save ipfs-bitswap, it can also be used directly in the browser.
The source is available for download from GitHub. Alternatively, you can install using npm:
$ npm install --save ipfs-bitswap
You can then
require() ipfs-bitswap as normal:
const ipfsBitswap = require('ipfs-bitswap')
In the Browser
Ipfs-bitswap should work in any ES2015 environment out of the box.
The portable versions of ipfs-bitswap, including
index.min.js, are included in the
/dist folder. Ipfs-bitswap can also be found on unpkg.com under
wantlistForPeer(peerId: PeerId): Wantlist
Return the current wantlist for a given
ledgerForPeer(peerId: PeerId): Object?
Return ledger information for a given
get(cid: CID, callback: function (Error, Block)): void
Fetch a given block by cid. If the block is in the local blockstore it is returned, otherwise the block is added to the wantlist and returned once another node sends it to us.
callback: function (Error, Block):
Fetch a a list of blocks by cid. If the blocks are in the local blockstore they are returned, otherwise the blocks are added to the wantlist and returned once another node sends them to us.
put(block: Block, callback: function (Error)): void
Put the given block to the underlying blockstore and send it to nodes that have it in their wantlist.
Put the given blocks to the underlying blockstore and send it to nodes that have it them their wantlist.
Get the current list of wants.
start(callback: function (Error)): void
Start the bitswap node.