decodeRecords function

List<Map<String, dynamic>> decodeRecords(
  1. List<Map<String, dynamic>> records
)

Decodes any base64-encoded fields in the list of record maps. If a value is a map with {"encoding": "base64", "data": ...}, it will be replaced with a Uint8List containing the decoded bytes.

Implementation

List<Map<String, dynamic>> decodeRecords(List<Map<String, dynamic>> records) {
  for (final r in records) {
    for (final k in r.keys.toList()) {
      final v = r[k];
      if (v is Map<String, dynamic>) {
        final encoding = v["encoding"];
        if (encoding == "base64") {
          final data = v["data"] as String;
          r[k] = base64Decode(data);
        } else {
          throw ArgumentError("Invalid encoding type $encoding");
        }
      }
    }
  }
  return records;
}