fmtBytes function

String fmtBytes(
  1. int bytes
)

Formats bytes as a human-readable string with one decimal place.

Used by CLI adapters that display memory sizes (e.g. fdb mem).

Implementation

String fmtBytes(int bytes) {
  if (bytes >= 1024 * 1024 * 1024) return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(1)} GB';
  if (bytes >= 1024 * 1024) return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
  if (bytes >= 1024) return '${(bytes / 1024).toStringAsFixed(1)} KB';
  return '$bytes B';
}