read method

Readable read(
  1. num? value
)

Formats the given value as a Readable instance using the byte unit.

If the unit is auto, it automatically determines the most appropriate unit based on the value.

Example:

Readable readable = ByteUnits.mb.read(2048);
print(readable); // Output: 2.00 MB

Implementation

Readable read(num? value) {
  value ??= 0;
  if (this == auto) {
    if (value <= 0) return Readable(0, bytes.name);
    final i = (value == 0) ? 0 : (log(value) / log(1024)).floor();
    final u = this[i];
    return Readable(value / u.unit, u.name, 2);
  } else {
    return Readable(value / unit, name, 2);
  }
}