BinarySize class
Represents a data size in bytes and provides human-readable formatting.
BinarySize converts raw byte counts into formatted strings like "1.00 KiB" and can parse such strings back into byte values.
Three byte-size standards are supported via standard:
- BinarySizeIecStandard (default): binary prefixes (KiB, MiB, GiB, …), where 1 KiB = 1024 B.
- BinarySizeJedecStandard: binary values with SI-named units (KB, MB, GB, …), where 1 KB = 1024 B.
- BinarySizeSiStandard: decimal prefixes (kB, MB, GB, …), where 1 kB = 1000 B.
Arithmetic and comparison operators are overloaded on bytesCount, using BigInt to avoid precision loss.
final size = BinarySize()..bytesCount = BigInt.from(1536);
print(size.displayText); // "1.50 KiB" (with default IEC standard)
// Parse a human-readable string back.
final parsed = BinarySize.parse('3.25 GiB');
print(parsed!.bytesCount); // BigInt 3489660928
Constructors
Properties
- bytesCount ↔ BigInt
-
The raw byte count represented by this BinarySize.
getter/setter pair
- displayText → String
-
A human-readable representation of this byte size.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- standard ↔ BinarySizeConventionStandard
-
The byte-size convention standard used for formatting and parsing.
getter/setter pair
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator *(
BinarySize other) → BinarySize -
Returns a new BinarySize whose bytesCount is the product of this and
other's byte counts. -
operator +(
BinarySize other) → BinarySize -
Returns a new BinarySize whose bytesCount is the sum of this and
other's byte counts. -
operator -(
BinarySize other) → BinarySize -
Returns a new BinarySize whose bytesCount is the difference between
this and
other's byte counts. -
operator /(
BinarySize other) → double -
Returns the ratio of this bytesCount to
other's bytesCount as a double. -
operator <(
BinarySize other) → bool -
Whether this bytesCount is strictly less than
other's. -
operator <=(
BinarySize other) → bool -
Whether this bytesCount is less than or equal to
other's. -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator >(
BinarySize other) → bool -
Whether this bytesCount is strictly greater than
other's. -
operator >=(
BinarySize other) → bool -
Whether this bytesCount is greater than or equal to
other's.
Static Methods
-
parse(
String size, {BinarySizeConventionStandard? fallbackStandard}) → BinarySize? - Parses a human-readable size string into a BinarySize object.