decode static method

List<int> decode(
  1. String data, [
  2. String? customAlphabet
])

Decode the provided Base32 string into a List

Implementation

static List<int> decode(String data, [String? customAlphabet]) {
  try {
    /// Add padding characters to the input data as needed.
    data = _Base32Utils.addPadding(data);

    /// If a custom alphabet is specified, translate the input data to the standard Base32 alphabet.
    if (customAlphabet != null) {
      data = _Base32Utils.translateAlphabet(
          data, customAlphabet, _Base32Const.alphabet);
    }

    /// Decode the Base32 string and obtain the decoded bytes.
    final decodedBytes = _Base32Utils._b32decode(_Base32Const.alphabet, data);

    /// Return the decoded bytes as a List<int>.
    return List<int>.from(decodedBytes);
  } catch (ex) {
    /// Handle exceptions by throwing an error for invalid Base32 strings.
    throw const ArgumentException('Invalid Base32 string');
  }
}