lookup method

Future<CachedAsset?> lookup(
  1. String bundleUrl
)

The cached skin for bundleUrl, or null on any miss or failure.

Implementation

Future<CachedAsset?> lookup(String bundleUrl) async {
  try {
    final key = skinKeyFromUrl(bundleUrl);
    if (key == null) return null;
    final file = await _entryFile(key.skinId, key.version);
    if (!await file.exists()) return null;
    final length = await file.length();
    if (length <= 0 || length > skinFileMaxBytes) return null;
    final bytes = await file.readAsBytes();
    if (bytes.isEmpty || bytes.length > skinFileMaxBytes) return null;
    try {
      await file.setLastModified(DateTime.now());
    } catch (_) {
      // A stale mtime only affects eviction order.
    }
    return CachedAsset(
        'text/html', const {'Content-Security-Policy': skinCspHeader}, bytes);
  } catch (_) {
    return null;
  }
}