decode static method
String
decode(
- List<
int> value, { - StringEncoding type = StringEncoding.utf8,
- bool allowInvalidOrMalformed = false,
- bool b64NoPadding = false,
- 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:
final decode = UTF8Decoder.decode(
value,
allowMalformed: allowInvalidOrMalformed,
);
return decode;
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:
final decode = ASCIIDecoder.decode(
value,
allowMalformed: allowInvalidOrMalformed,
);
return decode;
}
} catch (e) {
throw ArgumentException.invalidOperationArguments(
"decode",
name: "value",
reason: "Failed to decode bytes as ${type.name}",
);
}
}