IPLD Blockstore in memory JavaScript Implementation
Blockstore - A Blockstore provides persistance for IPLD Blocks
> npm install ipld-blockstore
const Block = require('ipld-blockstore')
const Block = require('ipld-block')
const Blockstore = require('ipld-blockstore')
// Create a blockstore
const blockstore = new Blockstore()
// create a block and store it
const cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
const block = new Block(Buffer.from('hello'), cid)
blockstore.put(block);
// get the block
const block2 = blockstore.get(cid)
// delete the block
blockstore.delete(cid)
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
const Block = require('ipld-blockstore')
Loading this module through a script tag will make the IpldBlockstore
obj available in
the global namespace.
<script src="https://unpkg.com/ipld-blockstore/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipld-blockstore/dist/index.js"></script>
const Block = require('ipld-blockstore')
Creates a new blockstore.
returns a Promise that resolves to the requested block or throws Error with code 'ERR_NOT_FOUND' if not found
stores the block and returns a Promise that resolves to void
deletes the Block for cid if present and returns a Promise that resolves to void or throws Error with code 'ERR_NOT_FOUND' if not found
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.