$ npm install ipfs-merkle-dag
JavaScript Implementation of the DAGService and DAGNode data structure
$ npm i ipfs-merkle-dag
┌────────────────────┐
│ DAGService │
└────────────────────┘
│
▼
┌────────────────────┐
│ BlockService │
└────────────────────┘
DAGService - The DAGService offers an interface to interact directly with a MerkleDAG object (composed by one or more DAGNodes that are linked), using the BlockService to store and fetch the DAGNodes as it needs them
A DAGNode and DAGLink are data structures made available on this module.
const ipfsMDAG = require('ipfs-merkle-dag')
// then, to access each of the components
ipfsMDAG.DAGService
ipfsMDAG.DAGNode
ipfsMDAG.DAGLink
Create a new DAGNode
var node = new ipfsMDAG.DAGNode([<data>, <[links]>])
addNodeLinkcreates a link on node A to node B by using node B to get its multihash
addRawLinkcreates a link on node A to node B by using directly node B multihash
updateNodeLinkupdates a link on the node. caution this method returns a copy of the MerkleDAG node
removeNodeLinkremoves a link from the node by name
removeNodeLinkByHashremoves a link from the node by the hash of the linked node
copycreates a copy of the MerkleDAG Node
size(property) size of the node, in bytes
links(property) an array of
DAGLinks belonging to the node
multihashreturns the multihash (default: sha2-256)
marshalreturns a protobuf serialized version, compatible with go-ipfs MerkleDAG
unMarshaldeserializes a node encoded using protobuf
getPBNodeused internally
makeLinkused internally
Create a new DAGLink
var link = new ipfsMDAG.DAGLink(<name>, <size>, <hash>)
putstores the node
putStreamstores nodes using a writable pull-stream
getfetches a node by its multihash
getStreamfetches a node as a pull-stream
getRecursivefetches a node and all of its links (if possible)
getRecursiveStreamfetches a node and all of its links (if possible) as pull-stream
removedeletes a node
MIT © IPFS
© 2010 - cnpmjs.org x YWFE | Home | YWFE