formatFileSize property
Returns a formatted string representation of the file size.
The file size is represented in bytes and is formatted as follows:
- If the size is less than 1024 bytes, it is returned as is with the suffix "bytes".
- If the size is between 1024 bytes (inclusive) and 1024^2 bytes (exclusive), it is converted to kilobytes (KB) and returned with two decimal places.
- If the size is between 1024^2 bytes (inclusive) and 1024^3 bytes (exclusive), it is converted to megabytes (MB) and returned with two decimal places.
- If the size is between 1024^3 bytes (inclusive) and 1024^4 bytes (exclusive), it is converted to gigabytes (GB) and returned with two decimal places.
- If the size is between 1024^4 bytes (inclusive) and 1024^5 bytes (exclusive), it is converted to terabytes (TB) and returned with two decimal places.
- If the size is greater than or equal to 1024^5 bytes, it is converted to petabytes (PB) and returned with two decimal places.
Implementation
String get formatFileSize {
if (isBlank) {
return blankIfNull;
}
if (isNumber) {
return toDouble!.formatFileSize;
}
return this;
}