Skip to content

Latest commit

 

History

History
132 lines (90 loc) · 3.86 KB

README.md

File metadata and controls

132 lines (90 loc) · 3.86 KB

js-ipld-blockstore

standard-readme compliant Travis CI Coverage Status Dependency Status js-standard-style

IPLD Blockstore in memory JavaScript Implementation

Blockstore - A Blockstore provides persistance for IPLD Blocks

Lead Maintainer

Chris Hafey

Table of Contents

Install

npm

> npm install ipld-blockstore

Usage

Node.js

const Block = require('ipld-blockstore')

Example

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)

Browser: Browserify, Webpack, other bundlers

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')

Browser: <script> Tag

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>

API

const Block = require('ipld-blockstore')

Blockstore

new Blockstore()

Creates a new blockstore.

Promise<Block> blockstore.get(cid:CID)

returns a Promise that resolves to the requested block or throws Error with code 'ERR_NOT_FOUND' if not found

Promise<void> blockstore.put(block:Block)

stores the block and returns a Promise that resolves to void

Promise<void> blockstore.delete(cid:CID)

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

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT