decode static method

String decode(
  1. List<int> value, {
  2. StringEncoding type = StringEncoding.utf8,
  3. bool allowInvalidOrMalformed = false,
  4. bool b64NoPadding = false,
  5. Base58Alphabets base58alphabets = Base58Alphabets.bitcoin,
})

Decodes a list of bytes value into a string using the specified type.

The type parameter determines the decoding type to use, with UTF-8 being the default. Returns the decoded string.

Implementation

static String decode(List<int> value,
    {StringEncoding type = StringEncoding.utf8,
    bool allowInvalidOrMalformed = false,
    bool b64NoPadding = false,
    Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) {
  value = value.asBytes;
  try {
    switch (type) {
      case StringEncoding.utf8:
        return utf8.decode(value, allowMalformed: allowInvalidOrMalformed);
      case StringEncoding.base64:
        return B64Encoder.encode(value, noPadding: b64NoPadding);
      case StringEncoding.base64UrlSafe:
        return B64Encoder.encode(value,
            urlSafe: true, noPadding: b64NoPadding);
      case StringEncoding.base58:
        return Base58Encoder.encode(value, base58alphabets);
      case StringEncoding.base58Check:
        return Base58Encoder.checkEncode(value, base58alphabets);
      case StringEncoding.hex:
        return BytesUtils.toHexString(value);
      case StringEncoding.ascii:
        return ascii.decode(value, allowInvalid: allowInvalidOrMalformed);
    }
  } catch (e) {
    throw ArgumentException("Failed to convert bytes as ${type.name}",
        details: {"error": e.toString()});
  }
}