readMeta method

Future<Map<String, Object?>> readMeta()

The content of the session meta line, or an empty map if absent.

Implementation

Future<Map<String, Object?>> readMeta() async {
  for (final file in files) {
    if (!_isRegularFile(file)) continue;

    final firstLine = await file
        .openRead()
        .transform(utf8.decoder)
        .transform(const LineSplitter())
        .firstWhere((_) => true, orElse: () => '');

    try {
      final decoded = jsonDecode(firstLine);
      if (decoded is Map<String, Object?>) {
        final meta = decoded[FileLogCodec.metaKey];
        if (meta is Map<String, Object?>) return meta;
      }
    } on FormatException {
      // Not a meta line — treat the session as having no metadata.
    }

    return const {};
  }

  return const {};
}