init method
Initializes the MFS by loading the root CID from the datastore or creating an empty root directory if it doesn't exist.
Implementation
Future<void> init() async {
final rootCidBytes = await _datastore.get(Key(_rootKey));
if (rootCidBytes != null) {
_rootCid = CID.fromBytes(rootCidBytes);
} else {
final dirManager = IPFSDirectoryManager();
final node = dirManager.build();
final data = marshalDagPBNode(node);
_rootCid = await CID.fromContent(data, codec: 'dag-pb');
await _blockStore.putBlock(
Block(cid: _rootCid!, data: data, format: 'dag-pb'),
);
await _datastore.put(Key(_rootKey), _rootCid!.toBytes());
}
}