toText method

String toText()

Implementation

String toText() {
  final checksumArrayBuf = ByteData(4);

  checksumArrayBuf.setUint32(0, getCrc32(_arr.buffer));

  final checksum = checksumArrayBuf.buffer.asUint8List();

  final bytes = Uint8List.fromList(_arr);
  final array = Uint8List.fromList([...checksum, ...bytes]);

  final result = base32Encode(array);
  var reg = RegExp(r".{1,5}");
  final matches = reg.allMatches(result);
  if (matches.isEmpty) {
    // This should only happen if there's no character, which is unreachable.
    throw "no character found";
  }
  return matches.map((e) => e.group(0)).join('-');
}