/// Created by Haoyi on 2023/4/22

class SizeUtils {
  static const double _byte = 1;
  static const double _kb = 1024;
  static const double _mb = 1048576;
  static const double _gb = 1073741824;

  static String byte2FitSize(final int byteSize, {int precision = 1}) {
    if (byteSize < 0) {
      return "0";
    } else if (byteSize < _kb) {
      return "${byteSize}B";
    } else if (byteSize < _mb) {
      return "${(byteSize / _kb).toStringAsFixed(precision)}KB";
    } else if (byteSize < _gb) {
      return "${(byteSize / _mb).toStringAsFixed(precision)}MB";
    } else {
      return "${(byteSize / _gb).toStringAsFixed(precision)}GB";
    }
  }
}
