get method

Future<Uint8List?> get(
  1. String cidString
)

Gets data by CID string.

Implementation

Future<Uint8List?> get(String cidString) async {
  // 1. Try local storage via BlockStore
  final response = await _blockStore.getBlock(cidString);
  if (response.found && response.hasBlock()) {
    return Block.fromProto(response.block).data;
  }

  // 2. Fallback to Bitswap
  if (_router.connectedPeers.isNotEmpty) {
    try {
      final block = await _bitswap.wantBlock(cidString);
      if (block != null) {
        // Block is automatically added to store by BitswapHandler when received
        return block.data;
      }
    } catch (e) {
      // Networking failed or timed out
    }
  }

  return null;
}