Information final
final class Information extends Quantity<Information>A quantity representing digital information — measured in bytes or bits, with both metric (SI) and binary (IEC) prefix variants.
Metric prefixes (kilo, mega, giga, …) use powers of 10 (10³, 10⁶, 10⁹, …). Binary prefixes (kibi, mebi, gibi, …) use powers of 2 (2¹⁰, 2²⁰, 2³⁰, …).
The internal base unit is bytes (B). Bit-based units use a conversion factor of BitsConversionFactor (0.125 = 1/8).
Inheritance
Object → Quantity<A extends Quantity<A>> → Information
Constructors
Information()
Information(double value, UnitOfMeasure<Information> unit)Implementation
Information(super.value, super.unit);Properties
hashCode no setter inherited
int get hashCodeThe hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Quantity.
Implementation
@override
int get hashCode => Object.hash(value, unit);runtimeType no setter inherited
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;toBits no setter
Information get toBitsConverts this to bits (bit).
Implementation
Information get toBits => to(bits).bits;toBytes no setter
Information get toBytesConverts this to bytes (B).
Implementation
Information get toBytes => to(bytes).bytes;toExabits no setter
Information get toExabitsConverts this to exabits (Ebit) — 10¹⁸ bits.
Implementation
Information get toExabits => to(exabits).exabits;toExabytes no setter
Information get toExabytesConverts this to exabytes (EB) — 10¹⁸ bytes.
Implementation
Information get toExabytes => to(exabytes).exabytes;toExbibits no setter
Information get toExbibitsConverts this to exbibits (Eibit) — 2⁶⁰ bits.
Implementation
Information get toExbibits => to(exbibits).exbibits;toExbibytes no setter
Information get toExbibytesConverts this to exbibytes (EiB) — 2⁶⁰ bytes.
Implementation
Information get toExbibytes => to(exbibytes).exbibytes;toGibibits no setter
Information get toGibibitsConverts this to gibibits (Gibit) — 2³⁰ bits.
Implementation
Information get toGibibits => to(gibibits).gibibits;toGibibytes no setter
Information get toGibibytesConverts this to gibibytes (GiB) — 2³⁰ bytes.
Implementation
Information get toGibibytes => to(gibibytes).gibibytes;toGigabits no setter
Information get toGigabitsConverts this to gigabits (Gbit) — 10⁹ bits.
Implementation
Information get toGigabits => to(gigabits).gigabits;toGigabytes no setter
Information get toGigabytesConverts this to gigabytes (GB) — 10⁹ bytes.
Implementation
Information get toGigabytes => to(gigabytes).gigabytes;toKibibits no setter
Information get toKibibitsConverts this to kibibits (Kibit) — 2¹⁰ bits.
Implementation
Information get toKibibits => to(kibibits).kibibits;toKibibytes no setter
Information get toKibibytesConverts this to kibibytes (KiB) — 2¹⁰ bytes.
Implementation
Information get toKibibytes => to(kibibytes).kibibytes;toKilobits no setter
Information get toKilobitsConverts this to kilobits (Kbit) — 10³ bits.
Implementation
Information get toKilobits => to(kilobits).kilobits;toKilobytes no setter
Information get toKilobytesConverts this to kilobytes (KB) — 10³ bytes.
Implementation
Information get toKilobytes => to(kilobytes).kilobytes;toMebibits no setter
Information get toMebibitsConverts this to mebibits (Mibit) — 2²⁰ bits.
Implementation
Information get toMebibits => to(mebibits).mebibits;toMebibytes no setter
Information get toMebibytesConverts this to mebibytes (MiB) — 2²⁰ bytes.
Implementation
Information get toMebibytes => to(mebibytes).mebibytes;toMegabits no setter
Information get toMegabitsConverts this to megabits (Mbit) — 10⁶ bits.
Implementation
Information get toMegabits => to(megabits).megabits;toMegabytes no setter
Information get toMegabytesConverts this to megabytes (MB) — 10⁶ bytes.
Implementation
Information get toMegabytes => to(megabytes).megabytes;toOctets no setter
Information get toOctetsConverts this to octets (o) — equivalent to bytes.
Implementation
Information get toOctets => to(octets).octets;toPebibits no setter
Information get toPebibitsConverts this to pebibits (Pibit) — 2⁵⁰ bits.
Implementation
Information get toPebibits => to(pebibits).pebibits;toPebibytes no setter
Information get toPebibytesConverts this to pebibytes (PiB) — 2⁵⁰ bytes.
Implementation
Information get toPebibytes => to(pebibytes).pebibytes;toPetabits no setter
Information get toPetabitsConverts this to petabits (Pbit) — 10¹⁵ bits.
Implementation
Information get toPetabits => to(petabits).petabits;toPetabytes no setter
Information get toPetabytesConverts this to petabytes (PB) — 10¹⁵ bytes.
Implementation
Information get toPetabytes => to(petabytes).petabytes;toTebibits no setter
Information get toTebibitsConverts this to tebibits (Tibit) — 2⁴⁰ bits.
Implementation
Information get toTebibits => to(tebibits).tebibits;toTebibytes no setter
Information get toTebibytesConverts this to tebibytes (TiB) — 2⁴⁰ bytes.
Implementation
Information get toTebibytes => to(tebibytes).tebibytes;toTerabits no setter
Information get toTerabitsConverts this to terabits (Tbit) — 10¹² bits.
Implementation
Information get toTerabits => to(terabits).terabits;toTerabytes no setter
Information get toTerabytesConverts this to terabytes (TB) — 10¹² bytes.
Implementation
Information get toTerabytes => to(terabytes).terabytes;toYobibits no setter
Information get toYobibitsConverts this to yobibits (Yibit) — 2⁸⁰ bits.
Implementation
Information get toYobibits => to(yobibits).yobibits;toYobibytes no setter
Information get toYobibytesConverts this to yobibytes (YiB) — 2⁸⁰ bytes.
Implementation
Information get toYobibytes => to(yobibytes).yobibytes;toYottabits no setter
Information get toYottabitsConverts this to yottabits (Ybit) — 10²⁴ bits.
Implementation
Information get toYottabits => to(yottabits).yottabits;toYottabytes no setter
Information get toYottabytesConverts this to yottabytes (YB) — 10²⁴ bytes.
Implementation
Information get toYottabytes => to(yottabytes).yottabytes;toZebibits no setter
Information get toZebibitsConverts this to zebibits (Zibit) — 2⁷⁰ bits.
Implementation
Information get toZebibits => to(zebibits).zebibits;toZebibytes no setter
Information get toZebibytesConverts this to zebibytes (ZiB) — 2⁷⁰ bytes.
Implementation
Information get toZebibytes => to(zebibytes).zebibytes;toZettabits no setter
Information get toZettabitsConverts this to zettabits (Zbit) — 10²¹ bits.
Implementation
Information get toZettabits => to(zettabits).zettabits;toZettabytes no setter
Information get toZettabytesConverts this to zettabytes (ZB) — 10²¹ bytes.
Implementation
Information get toZettabytes => to(zettabytes).zettabytes;unit final inherited
final UnitOfMeasure<Information> unitThe unit of measure that value is expressed in.
Inherited from Quantity.
Implementation
final UnitOfMeasure<A> unit;value final inherited
final double valueThe raw numeric value of this quantity expressed in unit.
Inherited from Quantity.
Implementation
final double value;Methods
equivalentTo() inherited
bool equivalentTo(Quantity<Information> other)Returns true if this quantity represents the same physical magnitude as other, regardless of which unit each is expressed in.
Inherited from Quantity.
Implementation
bool equivalentTo(Quantity<A> other) => other.to(unit) == value;noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);to() inherited
double to(UnitOfMeasure<Information> uom)Converts this quantity to uom and returns the raw double value.
If uom equals unit, the current value is returned unchanged.
Inherited from Quantity.
Implementation
double to(UnitOfMeasure<A> uom) => uom == unit ? value : uom.convertTo(unit.convertFrom(value));toCoarsest()
Information toCoarsest()Returns this value expressed in the coarsest (most human-readable) unit within the same prefix family as the current unit.
Starting from the current unit, this repeatedly divides the value by 1 000 (for metric) or 1 024 (for binary) and moves up to the next larger unit as long as the result is ≥ 1. The four prefix families are kept separate: metric bytes, binary bytes, metric bits, and binary bits. A value already in the largest unit of its family (yottabytes, yobibytes, yottabits, or yobibits) is returned unchanged.
Example:
print(1_500_000.bytes.toCoarsest()); // 1.5 MB
print(1_048_576.bytes.toCoarsest()); // 1.0 MB (metric — not MiB)Implementation
// TODO: Go from bits to bytes if modulo 8 == 0?
Information toCoarsest() {
Information loop(double value, UnitOfMeasure<Information> unit) {
Information coarserOrThis(
UnitOfMeasure<Information> coarser,
int divider,
) {
if (value / divider >= 1) {
return loop(value / divider, coarser);
} else if (unit == this.unit) {
return this;
} else {
return Information(value, unit);
}
}
return switch (unit) {
// Metric Bytes
yottabytes => Information(value, unit),
zettabytes => coarserOrThis(yottabytes, MetricSystem.Kilo.toInt()),
exabytes => coarserOrThis(zettabytes, MetricSystem.Kilo.toInt()),
petabytes => coarserOrThis(exabytes, MetricSystem.Kilo.toInt()),
terabytes => coarserOrThis(petabytes, MetricSystem.Kilo.toInt()),
gigabytes => coarserOrThis(terabytes, MetricSystem.Kilo.toInt()),
megabytes => coarserOrThis(gigabytes, MetricSystem.Kilo.toInt()),
kilobytes => coarserOrThis(megabytes, MetricSystem.Kilo.toInt()),
bytes => coarserOrThis(kilobytes, MetricSystem.Kilo.toInt()),
// Binary Bytes
yobibytes => Information(value, unit),
zebibytes => coarserOrThis(yobibytes, BinarySystem.Kilo.toInt()),
exbibytes => coarserOrThis(zebibytes, BinarySystem.Kilo.toInt()),
pebibytes => coarserOrThis(exbibytes, BinarySystem.Kilo.toInt()),
tebibytes => coarserOrThis(pebibytes, BinarySystem.Kilo.toInt()),
gibibytes => coarserOrThis(tebibytes, BinarySystem.Kilo.toInt()),
mebibytes => coarserOrThis(gibibytes, BinarySystem.Kilo.toInt()),
kibibytes => coarserOrThis(mebibytes, BinarySystem.Kilo.toInt()),
// Metric Bits
yottabits => Information(value, unit),
zettabits => coarserOrThis(yottabits, MetricSystem.Kilo.toInt()),
exabits => coarserOrThis(zettabits, MetricSystem.Kilo.toInt()),
petabits => coarserOrThis(exabits, MetricSystem.Kilo.toInt()),
terabits => coarserOrThis(petabits, MetricSystem.Kilo.toInt()),
gigabits => coarserOrThis(terabits, MetricSystem.Kilo.toInt()),
megabits => coarserOrThis(gigabits, MetricSystem.Kilo.toInt()),
kilobits => coarserOrThis(megabits, MetricSystem.Kilo.toInt()),
bits => coarserOrThis(kilobits, MetricSystem.Kilo.toInt()),
// Binary Bits
yobibits => Information(value, unit),
zebibits => coarserOrThis(yobibits, BinarySystem.Kilo.toInt()),
exbibits => coarserOrThis(zebibits, BinarySystem.Kilo.toInt()),
pebibits => coarserOrThis(exbibits, BinarySystem.Kilo.toInt()),
tebibits => coarserOrThis(pebibits, BinarySystem.Kilo.toInt()),
gibibits => coarserOrThis(tebibits, BinarySystem.Kilo.toInt()),
mebibits => coarserOrThis(gibibits, BinarySystem.Kilo.toInt()),
kibibits => coarserOrThis(mebibits, BinarySystem.Kilo.toInt()),
_ => this,
};
}
return unit == yottabytes || unit == yobibytes || unit == yottabits || unit == yobibits
? this
: loop(value, unit);
}toString() inherited
String toString()A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Inherited from Quantity.
Implementation
@override
String toString() => '$value ${unit.symbol}';Operators
operator +()
Information operator +(Information that)Returns the sum of this and that in the units of this Information.
Implementation
Information operator +(Information that) => Information(value + that.to(unit), unit);operator -()
Information operator -(Information that)Returns the difference between this and that in the units of this Information.
Implementation
Information operator -(Information that) => Information(value - that.to(unit), unit);operator <() inherited
bool operator <(Information that)Returns true if this quantity is less than that.
that is converted to unit before comparing.
Inherited from Quantity.
Implementation
bool operator <(A that) => value < that.to(unit);operator <=() inherited
bool operator <=(Information that)Returns true if this quantity is less than or equal to that.
that is converted to unit before comparing.
Inherited from Quantity.
Implementation
bool operator <=(A that) => value <= that.to(unit);operator ==() inherited
bool operator ==(Object other)The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Quantity.
Implementation
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is Quantity<A> && other.value == value && other.unit == unit);operator >() inherited
bool operator >(Information that)Returns true if this quantity is greater than that.
that is converted to unit before comparing.
Inherited from Quantity.
Implementation
bool operator >(A that) => value > that.to(unit);operator >=() inherited
bool operator >=(Information that)Returns true if this quantity is greater than or equal to that.
that is converted to unit before comparing.
Inherited from Quantity.
Implementation
bool operator >=(A that) => value >= that.to(unit);Static Properties
units final
final Set<InformationUnit> unitsAll supported Information units.
Implementation
static final units = {
bytes,
octets,
kilobytes,
kibibytes,
megabytes,
mebibytes,
gigabytes,
gibibytes,
terabytes,
tebibytes,
petabytes,
pebibytes,
exabytes,
exbibytes,
zettabytes,
zebibytes,
yottabytes,
yobibytes,
bits,
kilobits,
kibibits,
megabits,
mebibits,
gigabits,
gibibits,
terabits,
tebibits,
petabits,
pebibits,
exabits,
exbibits,
zettabits,
zebibits,
yottabits,
yobibits,
};Static Methods
parse() override
Option<Information> parse(String s)Parses s into an Information, returning None if parsing fails.
Implementation
static Option<Information> parse(String s) => Quantity.parse(s, units);Constants
bits
const Bits bitsUnit for bits (bit) — 1/8 of a byte.
Implementation
static const bits = Bits._();BitsConversionFactor
const double BitsConversionFactorConversion factor from bytes to bits: 1 byte = 8 bits, so 1 bit = 0.125 bytes.
Implementation
static const BitsConversionFactor = 0.125;bytes
const Bytes bytesUnit for bytes (B) — the SI base unit of information.
Implementation
static const bytes = Bytes._();exabits
const Exabits exabitsUnit for exabits (Ebit) — 10¹⁸ bits.
Implementation
static const exabits = Exabits._();exabytes
const Exabytes exabytesUnit for exabytes (EB) — 10¹⁸ bytes.
Implementation
static const exabytes = Exabytes._();exbibits
const Exbibits exbibitsUnit for exbibits (Eibit) — 2⁶⁰ bits.
Implementation
static const exbibits = Exbibits._();exbibytes
const Exbibytes exbibytesUnit for exbibytes (EiB) — 2⁶⁰ bytes.
Implementation
static const exbibytes = Exbibytes._();gibibits
const Gibibits gibibitsUnit for gibibits (Gibit) — 2³⁰ bits.
Implementation
static const gibibits = Gibibits._();gibibytes
const Gibibytes gibibytesUnit for gibibytes (GiB) — 2³⁰ bytes.
Implementation
static const gibibytes = Gibibytes._();gigabits
const Gigabits gigabitsUnit for gigabits (Gbit) — 10⁹ bits.
Implementation
static const gigabits = Gigabits._();gigabytes
const Gigabytes gigabytesUnit for gigabytes (GB) — 10⁹ bytes.
Implementation
static const gigabytes = Gigabytes._();kibibits
const Kibibits kibibitsUnit for kibibits (Kibit) — 2¹⁰ bits.
Implementation
static const kibibits = Kibibits._();kibibytes
const Kibibytes kibibytesUnit for kibibytes (KiB) — 2¹⁰ = 1 024 bytes.
Implementation
static const kibibytes = Kibibytes._();kilobits
const Kilobits kilobitsUnit for kilobits (Kbit) — 10³ bits.
Implementation
static const kilobits = Kilobits._();kilobytes
const Kilobytes kilobytesUnit for kilobytes (KB) — 10³ bytes.
Implementation
static const kilobytes = Kilobytes._();mebibits
const Mebibits mebibitsUnit for mebibits (Mibit) — 2²⁰ bits.
Implementation
static const mebibits = Mebibits._();mebibytes
const Mebibytes mebibytesUnit for mebibytes (MiB) — 2²⁰ = 1 048 576 bytes.
Implementation
static const mebibytes = Mebibytes._();megabits
const Megabits megabitsUnit for megabits (Mbit) — 10⁶ bits.
Implementation
static const megabits = Megabits._();megabytes
const Megabytes megabytesUnit for megabytes (MB) — 10⁶ bytes.
Implementation
static const megabytes = Megabytes._();octets
const Octets octetsUnit for octets (o) — equivalent to bytes; common in networking contexts.
Implementation
static const octets = Octets._();pebibits
const Pebibits pebibitsUnit for pebibits (Pibit) — 2⁵⁰ bits.
Implementation
static const pebibits = Pebibits._();pebibytes
const Pebibytes pebibytesUnit for pebibytes (PiB) — 2⁵⁰ bytes.
Implementation
static const pebibytes = Pebibytes._();petabits
const Petabits petabitsUnit for petabits (Pbit) — 10¹⁵ bits.
Implementation
static const petabits = Petabits._();petabytes
const Petabytes petabytesUnit for petabytes (PB) — 10¹⁵ bytes.
Implementation
static const petabytes = Petabytes._();tebibits
const Tebibits tebibitsUnit for tebibits (Tibit) — 2⁴⁰ bits.
Implementation
static const tebibits = Tebibits._();tebibytes
const Tebibytes tebibytesUnit for tebibytes (TiB) — 2⁴⁰ bytes.
Implementation
static const tebibytes = Tebibytes._();terabits
const Terabits terabitsUnit for terabits (Tbit) — 10¹² bits.
Implementation
static const terabits = Terabits._();terabytes
const Terabytes terabytesUnit for terabytes (TB) — 10¹² bytes.
Implementation
static const terabytes = Terabytes._();yobibits
const Yobibits yobibitsUnit for yobibits (Yibit) — 2⁸⁰ bits.
Implementation
static const yobibits = Yobibits._();yobibytes
const Yobibytes yobibytesUnit for yobibytes (YiB) — 2⁸⁰ bytes.
Implementation
static const yobibytes = Yobibytes._();yottabits
const Yottabits yottabitsUnit for yottabits (Ybit) — 10²⁴ bits.
Implementation
static const yottabits = Yottabits._();yottabytes
const Yottabytes yottabytesUnit for yottabytes (YB) — 10²⁴ bytes.
Implementation
static const yottabytes = Yottabytes._();zebibits
const Zebibits zebibitsUnit for zebibits (Zibit) — 2⁷⁰ bits.
Implementation
static const zebibits = Zebibits._();zebibytes
const Zebibytes zebibytesUnit for zebibytes (ZiB) — 2⁷⁰ bytes.
Implementation
static const zebibytes = Zebibytes._();zettabits
const Zettabits zettabitsUnit for zettabits (Zbit) — 10²¹ bits.
Implementation
static const zettabits = Zettabits._();zettabytes
const Zettabytes zettabytesUnit for zettabytes (ZB) — 10²¹ bytes.
Implementation
static const zettabytes = Zettabytes._();