getFileData method

Future<Uint8List> getFileData(
  1. AdvImageCache key
)

Implementation

Future<Uint8List> getFileData(AdvImageCache key) async {
  String uid = key.url.hashCode.toString();
  Uint8List data;

  //search local copy
  final File file = await _getLocalFile(key.diskCacheDirName, uid);
  if (file.existsSync() && file.lengthSync() > 0) {
    data = file.readAsBytesSync();
    //background update
    _cacheAutoUpdate(file, key);
  } else {
    data = await _load(file, key);
  }

  if (data.length > 0) {
    //test valid image
    try {
      await PaintingBinding.instance.instantiateImageCodecWithSize(await ImmutableBuffer.fromUint8List(data));
      _updateMemCache(key, data);
    } catch (_) {
      clearItem(key.url, diskCacheDirName: key.diskCacheDirName);
      data = Uint8List(0);
    }
  }

  return data;
}