stat method
Retrieve metadata for a remote path.
Returns null when the object does not exist.
Implementation
@override
Future<CloudStorageStat?> stat(String path) async {
final key = _fullKey(path);
try {
final stream = client.listObjects(bucket, prefix: key, recursive: false);
await for (final result in stream) {
for (final obj in result.objects) {
final objectKey = obj.key ?? '';
if (objectKey == key) {
return CloudStorageStat(
type: FileSystemEntityType.file,
size: obj.size ?? 0,
modified: obj.lastModified,
);
}
}
}
} catch (_) {
// Ignore failures and try directory detection below.
}
final dirPrefix = key.isEmpty ? '' : (key.endsWith('/') ? key : '$key/');
try {
final stream = client.listObjects(
bucket,
prefix: dirPrefix,
recursive: false,
);
await for (final result in stream) {
for (final obj in result.objects) {
final objectKey = obj.key ?? '';
if (objectKey != dirPrefix && objectKey.startsWith(dirPrefix)) {
return CloudStorageStat(
type: FileSystemEntityType.directory,
size: 0,
);
}
}
}
} catch (_) {
// Ignore failures.
}
return null;
}