parseUpgradeBlob function

Future<Uint8List> parseUpgradeBlob (
  1. Uint8List blob
)

Implementation

Future<Uint8List> parseUpgradeBlob(Uint8List blob) async {
  final lines = utf8.decode(blob).split('\r\n');
  var records = lines
      .where((l) => l.isNotEmpty)
      .map(FileRecord.fromLine)
      .where((r) => FileRecord.RECORD_TYPE_DATAs.contains(r.tag))
      .toList();

  var start = records.first.address;
  var end = records.last.address + records.last.data.length;
  var result = List.filled(end - start, 0xFF);
  for (final r in records)
    result.setRange(r.address - start, r.address - start + r.data.length, r.data);
  return Uint8List.fromList(result);
}