decode static method

Uint8List decode(
  1. String input
)

Implementation

static Uint8List decode(String input) {
  if (input.isEmpty) {
    return Uint8List(0);
  }

  var remainderSize = input.length % encodedChunkSize;
  if (remainderSize == 1) {
    throw ArgumentError.value(input, "input", "has incorrect length");
  }

  if (decoding.keys.isEmpty) {
    for (int i = 0; i < encoding.length; ++i) {
      decoding[encoding[i]] = i;
    }
  }

  var buffer = Uint8List(input.length);
  for (var i = 0; i < input.length; ++i) {
    var found = decoding[input[i]];
    if (null == found) {
      throw Exception("Invalid character at position $i.");
    }
    buffer[i] = found;
  }

  var wholeChunkCount = (buffer.length / encodedChunkSize).truncate();

  var result = Uint8List(
      wholeChunkCount * chunkSize + (remainderSize == chunkSize ? 1 : 0));
  var resultIndex = 0;
  var wholeChunkLength = wholeChunkCount * encodedChunkSize;
  for (var i = 0; i < wholeChunkLength;) {
    var val =
        buffer[i++] + baseSize * buffer[i++] + baseSizeSquared * buffer[i++];
    result[resultIndex++] = (val / byteSize)
        .truncate(); //result is always in the range 0-255 - % ByteSize omitted.
    result[resultIndex++] = val % byteSize;
  }

  if (remainderSize == 0) return result;

  result[result.length - 1] = buffer[buffer.length - 2] +
      baseSize *
          buffer[buffer.length -
              1]; //result is always in the range 0-255 - % ByteSize omitted.
  return result;
}