parseByteSizeAuto function
ParsedByteSize
parseByteSizeAuto(
- String input, {
- ByteStandard standard = ByteStandard.si,
- RoundingMode rounding = RoundingMode.round,
- double thresholdBytes = 9.22e18,
Parses input and returns either ByteConverter or BigByteConverter
depending on thresholdBytes. Useful when inputs may exceed 64-bit range.
Values >= thresholdBytes are parsed and returned as ParsedBig.
Implementation
ParsedByteSize parseByteSizeAuto(
String input, {
ByteStandard standard = ByteStandard.si,
RoundingMode rounding = RoundingMode.round,
double thresholdBytes = 9.22e18, // ~2^63 for practical split
}) {
// Use big-aware parsing for accurate detection across all units
final preview = parseSizeBig(input: input, standard: standard);
final bytes = preview.valueInBytes.abs();
if (bytes >= thresholdBytes) {
// reparse via Big path for better precision then round
final big = BigByteConverter.parse(
input,
standard: standard,
rounding: rounding,
);
return ParsedBig(big);
}
return ParsedNormal(ByteConverter(preview.valueInBytes));
}