Skip to content

dignifiedquire/js-ipfs-blocks

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IPFS Blocks JavaScript Implementation

Dependency Status js-standard-style

JavaScript Implementation of the BlockService and Block data structure

Architecture

┌────────────────────┐
│   BlockService     │
└────────────────────┘
           │
     ┌─────┴─────┐
     ▼           ▼
┌─────────┐ ┌────────┐
│IPFS REPO│ │Exchange│
└─────────┘ └────────┘

BlockService - The BlockService uses IPFS Repo as the local datastore for blocks and an IPFS Exchange compliant implementation to fetch blocks from the network.

A Block is a data structure available on this module.

Usage

$ npm i ipfs-blocks
const ipfsBlocks = require('ipfs-blocks')

// then, to access each of the components
ipfsBlocks.BlockService
ipfsBlocks.Block

Block

Create a new block

var block = new blocks.Block('some data')
console.log(block.data) 
// It will print 'some data'
console.log(block.key)
// It will print the sha256 multihash of 'some data'

BlockService

Create a new block service

var bs = new ipfsBlocks.BlockService(<IPFS REPO instance> [, <IPFS Exchange>])
addBlock
bs.addBlock(block, function (err) {
  if (!err) {
    // block successfuly added
  }
})
addBlocks
bs.addBlocks(blockArray, function (err) {
  if (!err) {
    // blocks successfuly added
  }
})
getBlock
bs.getBlock(multihash, function (err, block) {
  if (!err) {
    // block successfuly retrieved
  }
})
getBlocks
bs.getBlocks(multihashArray, function (err, block) {
  if (!err) {
    // block successfuly retrieved
  }
})
deleteBlock
bs.deleteBlock(multihash, function (err) {
  if (!err) {
    // block successfuly deleted
  }
})
deleteBlocks
bs.deleteBlocks(multihashArray, function (err) {
  if (!err) {
    // blocks successfuly deleted
  }
})

About

JavaScript Implementation of Block and BlockService

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%