MerkleDAGNode class

A node in the IPFS Merkle DAG (Directed Acyclic Graph).

The Merkle DAG is the fundamental data structure in IPFS, where each node is identified by its content hash (cid) and can link to other nodes via links. This enables:

  • Content-addressable storage
  • Deduplication across the network
  • Cryptographic verification of data integrity

This class handles DAG-PB (protobuf) format with UnixFS data interpretation, automatically detecting directories and extracting metadata.

Example:

// Parse a node from bytes
final node = MerkleDAGNode.fromBytes(rawBytes);
// print('Is directory: ${node.isDirectory}');
// print('Has ${node.links.length} children');

// Access linked content
for (final link in node.links) {
  // print('  ${link.name}: ${link.cid}');
}

See also:

Constructors

MerkleDAGNode({required List<Link> links, required Uint8List data, bool isDirectory = false, int? mtime})
Creates a new MerkleDAGNode with the given components.

Properties

cid → CID
The content identifier for this node.
no setter
data → Uint8List
The raw data payload of this node.
final
hashCode → int
The hash code for this object.
no setterinherited
isDirectory → bool
Whether this node represents a directory.
final
The list of links (edges) to child nodes.
final
mtime → int?
Unix modification time in seconds, if available.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toBytes() → Uint8List
Converts the MerkleDAGNode to its byte representation. Note: This assumes data is already strictly formatted (e.g. valid UnixFS Data proto bytes). If you are building a node, ensure data is correct.
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

fromBytes(Uint8List bytes) → MerkleDAGNode
Creates a MerkleDAGNode from its byte representation (DAG-PB). Automatically inspects inner data to determine if it's a UnixFS Directory.