fromFile static method
- String path
Loads configuration from a JSON or YAML file.
JSON is the canonical on-disk format. Files ending in .yaml or .yml
are parsed as YAML and round-tripped through JSON for compatibility.
Implementation
static Future<IPFSConfig> fromFile(String path) async {
final content = await getPlatform().readString(path);
if (content == null) {
throw Exception('Configuration file not found: $path');
}
final lower = path.toLowerCase();
final Map<String, dynamic> jsonMap;
if (lower.endsWith('.yaml') || lower.endsWith('.yml')) {
final yaml = loadYaml(content);
jsonMap = json.decode(json.encode(yaml)) as Map<String, dynamic>;
} else {
jsonMap = json.decode(content) as Map<String, dynamic>;
}
return IPFSConfig.fromJson(jsonMap);
}