downloadRawFile method
Implementation
@override
Future<Uint8List> downloadRawFile(Multihash hash) async {
final locations = await fetchStorageLocationsFromServer(hash);
for (final loc in locations) {
try {
final res = await httpClient.get(Uri.parse(loc['parts'][0]));
if (res.statusCode != 200) {
throw 'HTTP ${res.statusCode}';
}
if (!areBytesEqual(
hash.hashBytes, crypto.hashBlake3Sync(res.bodyBytes))) {
throw 'Hash mismatch';
}
return res.bodyBytes;
} catch (e, st) {
// TODO Proper logging
print(e);
print(st);
}
}
throw 'Could not download file';
}