StorageMetadata.fromMap constructor

StorageMetadata.fromMap(
  1. Map<String, Object?> m
)

Implementation

factory StorageMetadata.fromMap(Map<String, Object?> m) {
  DateTime? at(String key) {
    final v = m[key];
    // The SDK reports these in milliseconds, and reports 0 for "not set" —
    // which as an epoch would be 1970 rather than absent.
    if (v is! int || v == 0) return null;
    return DateTime.fromMillisecondsSinceEpoch(v, isUtc: true);
  }

  return StorageMetadata(
    raw: m,
    bucket: m['bucket'] as String?,
    name: m['name'] as String?,
    path: m['path'] as String?,
    contentType: m['contentType'] as String?,
    cacheControl: m['cacheControl'] as String?,
    contentDisposition: m['contentDisposition'] as String?,
    contentEncoding: m['contentEncoding'] as String?,
    contentLanguage: m['contentLanguage'] as String?,
    md5Hash: m['md5Hash'] as String?,
    sizeBytes: (m['sizeBytes'] as int?) ?? 0,
    creationTime: at('creationTime'),
    updatedTime: at('updatedTime'),
    generation: (m['generation'] as int?) ?? 0,
    metadataGeneration: (m['metadataGeneration'] as int?) ?? 0,
    custom: {
      for (final e in ((m['custom'] as Map?) ?? const {}).entries)
        '${e.key}': '${e.value}',
    },
  );
}