readFile static method
- String relativePath
Read a file from the POD.
relativePath - Path relative to the data directory.
Example: places/places.json
Returns the file content as a string, or null if file doesn't exist.
Implementation
static Future<String?> readFile(String relativePath) async {
if (!await PodAuth.isLoggedIn()) {
debugPrint('PodFileSystem.readFile() - not logged in');
return null;
}
try {
final url = await PodPath.getFileUrl(relativePath);
final response = await PodHttp.get(url, accept: PodContentType.any);
if (response.isSuccess) {
return response.body;
} else if (response.isNotFound) {
debugPrint('PodFileSystem.readFile() - file not found: $relativePath');
return null;
} else {
debugPrint(
'PodFileSystem.readFile() - error ${response.statusCode}: ${response.body}',
);
return null;
}
} catch (e) {
debugPrint('PodFileSystem.readFile() - exception: $e');
return null;
}
}