stat method

  1. @override
Future<FileStat> stat(
  1. String path
)

Asynchronously calls the operating system's stat() function on path. Returns a Future which completes with a io.FileStat object containing the data returned by stat(). If the call fails, completes the future with a io.FileStat object with .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.

Implementation

@override
Future<io.FileStat> stat(String path) async {
  try {
    final resolved = await client.resolvePath(path);
    final metadata = resolved['metadata'] as Map<String, dynamic>?;
    final isFolder = resolved['type'] == 'folder';

    DateTime mTime;
    if (metadata != null && metadata['lastModified'] != null) {
      final lastMod = metadata['lastModified'];
      if (lastMod is int) {
        mTime = DateTime.fromMillisecondsSinceEpoch(lastMod);
      } else if (lastMod is String) {
        mTime = DateTime.tryParse(lastMod) ?? DateTime.now();
      } else {
        mTime = DateTime.now();
      }
    } else {
      mTime = DateTime.now();
    }

    return _VirtualFileStat(
      type: isFolder
          ? FileSystemEntityType.directory
          : FileSystemEntityType.file,
      size: isFolder ? -1 : (metadata?['size'] ?? 0),
      modified: mTime,
    );
  } catch (e) {
    return _VirtualFileStat(
      type: FileSystemEntityType.notFound,
      size: -1,
      modified: DateTime(0),
    );
  }
}