head method

  1. @override
Future<ObjectInfo?> head(
  1. String key
)
override

Get object metadata without reading the body (HeadObject).

Returns null if the key does not exist.

Implementation

@override
Future<ObjectInfo?> head(String key) async {
  checkNotDisposed();
  final info = await _inner.head(key);
  if (info == null) return null;

  // For encrypted files, report the PLAINTEXT size — ObjectInfo.size is
  // a logical-size guarantee. Sidecar first (no byte reads); otherwise
  // resolve from the header / ciphertext framing. A header that can't
  // even parse means the object can't be decrypted at all — surface
  // that as corruption instead of quietly reporting ciphertext size.
  if (info.metadata[_metaEncrypted] == 'true') {
    final sidecarSize = int.tryParse(info.metadata[_metaOriginalSize] ?? '');
    if (sidecarSize != null) {
      return info.copyWith(size: sidecarSize);
    }
    final g = await _resolveGeometry(key, info);
    return info.copyWith(size: g.originalSize);
  }

  return info;
}