convert method

  1. @override
String convert(
  1. List<int> bytes
)
override

Converts input and returns the result of the conversion.

Implementation

@override
String convert(List<int> bytes) {
  if (bytes.length == 0) return "";

  // copy bytes because we are going to change it
  bytes = new Uint8List.fromList(bytes);

  // count number of leading zeros
  int leadingZeroes = 0;
  while (leadingZeroes < bytes.length && bytes[leadingZeroes] == 0)
    leadingZeroes++;

  String output = "";
  int startAt = leadingZeroes;
  while (startAt < bytes.length) {
    int mod = _divmod58(bytes, startAt);
    if (bytes[startAt] == 0) startAt++;
    output = alphabet[mod] + output;
  }

  if (output.length > 0) {
    while (output[0] == alphabet[0])
      output = output.substring(1, output.length);
  }
  while (leadingZeroes-- > 0) output = alphabet[0] + output;

  return output;
}