detect static method
Detect encoding of bytedata
Implementation
static Encoding? detect(
List<int> bytes, {
/// falback encoding
Encoding? defaultEncoding,
/// detect list
List<Encoding>? orders,
/// return utf8 when has U+FEFF BOM, either return utf16
bool utf8BOM = true,
}) {
if (hasUtf16BeBom(bytes)) {
return utf8BOM ? utf8 : utf16;
}
if (hasUtf16LeBom(bytes)) {
return utf16;
}
if (hasUtf32beBom(bytes)) {
return utf32;
}
for (Encoding encoding in (orders ?? defaultDetectOrder)) {
if (canDecode(encoding, bytes)) {
return encoding;
}
}
return defaultEncoding;
}