getImageByHash method

Future<ImageData<Object>?> getImageByHash(
  1. String hash, {
  2. bool compressed = false,
  3. Data? owner,
})

Implementation

Future<ImageData?> getImageByHash(String hash,
    {bool compressed = false, Data? owner}) async {
  final isPath = hash.contains('/');
  final scope = _scopeForData(owner);
  List<String> candidates = [];
  if (!isPath && scope.isNotEmpty) {
    final scoped = '$scope/$hash';
    candidates.add(compressed
        ? '$scope/${OP.convertToCompressedHashName(hash)}'
        : scoped);
  }
  if (compressed) {
    candidates.add(OP.convertToCompressedHashName(hash));
  }
  candidates.add(hash);

  for (final name in candidates) {
    final img =
        await readImage(name, cacheSize: compressed ? CACHESIZE : null);
    if (img != null) return ImageData(img, id: hash);
  }
  throw Exception("no img cached");
}