Skip to content

Information final

finalclassInformationextendsQuantity<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(doublevalue,UnitOfMeasure<Information>unit)
Implementation
dart
Information(super.value, super.unit);

Properties

hashCode no setter inherited

intgethashCode

The 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
dart
@override
int get hashCode => Object.hash(value, unit);

runtimeType no setter inherited

TypegetruntimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
dart
external Type get runtimeType;

toBits no setter

InformationgettoBits

Converts this to bits (bit).

Implementation
dart
Information get toBits => to(bits).bits;

toBytes no setter

InformationgettoBytes

Converts this to bytes (B).

Implementation
dart
Information get toBytes => to(bytes).bytes;

toExabits no setter

InformationgettoExabits

Converts this to exabits (Ebit) — 10¹⁸ bits.

Implementation
dart
Information get toExabits => to(exabits).exabits;

toExabytes no setter

InformationgettoExabytes

Converts this to exabytes (EB) — 10¹⁸ bytes.

Implementation
dart
Information get toExabytes => to(exabytes).exabytes;

toExbibits no setter

InformationgettoExbibits

Converts this to exbibits (Eibit) — 2⁶⁰ bits.

Implementation
dart
Information get toExbibits => to(exbibits).exbibits;

toExbibytes no setter

InformationgettoExbibytes

Converts this to exbibytes (EiB) — 2⁶⁰ bytes.

Implementation
dart
Information get toExbibytes => to(exbibytes).exbibytes;

toGibibits no setter

InformationgettoGibibits

Converts this to gibibits (Gibit) — 2³⁰ bits.

Implementation
dart
Information get toGibibits => to(gibibits).gibibits;

toGibibytes no setter

InformationgettoGibibytes

Converts this to gibibytes (GiB) — 2³⁰ bytes.

Implementation
dart
Information get toGibibytes => to(gibibytes).gibibytes;

toGigabits no setter

InformationgettoGigabits

Converts this to gigabits (Gbit) — 10⁹ bits.

Implementation
dart
Information get toGigabits => to(gigabits).gigabits;

toGigabytes no setter

InformationgettoGigabytes

Converts this to gigabytes (GB) — 10⁹ bytes.

Implementation
dart
Information get toGigabytes => to(gigabytes).gigabytes;

toKibibits no setter

InformationgettoKibibits

Converts this to kibibits (Kibit) — 2¹⁰ bits.

Implementation
dart
Information get toKibibits => to(kibibits).kibibits;

toKibibytes no setter

InformationgettoKibibytes

Converts this to kibibytes (KiB) — 2¹⁰ bytes.

Implementation
dart
Information get toKibibytes => to(kibibytes).kibibytes;

toKilobits no setter

InformationgettoKilobits

Converts this to kilobits (Kbit) — 10³ bits.

Implementation
dart
Information get toKilobits => to(kilobits).kilobits;

toKilobytes no setter

InformationgettoKilobytes

Converts this to kilobytes (KB) — 10³ bytes.

Implementation
dart
Information get toKilobytes => to(kilobytes).kilobytes;

toMebibits no setter

InformationgettoMebibits

Converts this to mebibits (Mibit) — 2²⁰ bits.

Implementation
dart
Information get toMebibits => to(mebibits).mebibits;

toMebibytes no setter

InformationgettoMebibytes

Converts this to mebibytes (MiB) — 2²⁰ bytes.

Implementation
dart
Information get toMebibytes => to(mebibytes).mebibytes;

toMegabits no setter

InformationgettoMegabits

Converts this to megabits (Mbit) — 10⁶ bits.

Implementation
dart
Information get toMegabits => to(megabits).megabits;

toMegabytes no setter

InformationgettoMegabytes

Converts this to megabytes (MB) — 10⁶ bytes.

Implementation
dart
Information get toMegabytes => to(megabytes).megabytes;

toOctets no setter

InformationgettoOctets

Converts this to octets (o) — equivalent to bytes.

Implementation
dart
Information get toOctets => to(octets).octets;

toPebibits no setter

InformationgettoPebibits

Converts this to pebibits (Pibit) — 2⁵⁰ bits.

Implementation
dart
Information get toPebibits => to(pebibits).pebibits;

toPebibytes no setter

InformationgettoPebibytes

Converts this to pebibytes (PiB) — 2⁵⁰ bytes.

Implementation
dart
Information get toPebibytes => to(pebibytes).pebibytes;

toPetabits no setter

InformationgettoPetabits

Converts this to petabits (Pbit) — 10¹⁵ bits.

Implementation
dart
Information get toPetabits => to(petabits).petabits;

toPetabytes no setter

InformationgettoPetabytes

Converts this to petabytes (PB) — 10¹⁵ bytes.

Implementation
dart
Information get toPetabytes => to(petabytes).petabytes;

toTebibits no setter

InformationgettoTebibits

Converts this to tebibits (Tibit) — 2⁴⁰ bits.

Implementation
dart
Information get toTebibits => to(tebibits).tebibits;

toTebibytes no setter

InformationgettoTebibytes

Converts this to tebibytes (TiB) — 2⁴⁰ bytes.

Implementation
dart
Information get toTebibytes => to(tebibytes).tebibytes;

toTerabits no setter

InformationgettoTerabits

Converts this to terabits (Tbit) — 10¹² bits.

Implementation
dart
Information get toTerabits => to(terabits).terabits;

toTerabytes no setter

InformationgettoTerabytes

Converts this to terabytes (TB) — 10¹² bytes.

Implementation
dart
Information get toTerabytes => to(terabytes).terabytes;

toYobibits no setter

InformationgettoYobibits

Converts this to yobibits (Yibit) — 2⁸⁰ bits.

Implementation
dart
Information get toYobibits => to(yobibits).yobibits;

toYobibytes no setter

InformationgettoYobibytes

Converts this to yobibytes (YiB) — 2⁸⁰ bytes.

Implementation
dart
Information get toYobibytes => to(yobibytes).yobibytes;

toYottabits no setter

InformationgettoYottabits

Converts this to yottabits (Ybit) — 10²⁴ bits.

Implementation
dart
Information get toYottabits => to(yottabits).yottabits;

toYottabytes no setter

InformationgettoYottabytes

Converts this to yottabytes (YB) — 10²⁴ bytes.

Implementation
dart
Information get toYottabytes => to(yottabytes).yottabytes;

toZebibits no setter

InformationgettoZebibits

Converts this to zebibits (Zibit) — 2⁷⁰ bits.

Implementation
dart
Information get toZebibits => to(zebibits).zebibits;

toZebibytes no setter

InformationgettoZebibytes

Converts this to zebibytes (ZiB) — 2⁷⁰ bytes.

Implementation
dart
Information get toZebibytes => to(zebibytes).zebibytes;

toZettabits no setter

InformationgettoZettabits

Converts this to zettabits (Zbit) — 10²¹ bits.

Implementation
dart
Information get toZettabits => to(zettabits).zettabits;

toZettabytes no setter

InformationgettoZettabytes

Converts this to zettabytes (ZB) — 10²¹ bytes.

Implementation
dart
Information get toZettabytes => to(zettabytes).zettabytes;

unit final inherited

The unit of measure that value is expressed in.

Inherited from Quantity.

Implementation
dart
final UnitOfMeasure<A> unit;

value final inherited

finaldoublevalue

The raw numeric value of this quantity expressed in unit.

Inherited from Quantity.

Implementation
dart
final double value;

Methods

equivalentTo() inherited

boolequivalentTo(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
dart
bool equivalentTo(Quantity<A> other) => other.to(unit) == value;

noSuchMethod() inherited

dynamicnoSuchMethod(Invocationinvocation)

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:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This 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:

dart
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
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);

to() inherited

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
dart
double to(UnitOfMeasure<A> uom) => uom == unit ? value : uom.convertTo(unit.convertFrom(value));

toCoarsest()

InformationtoCoarsest()

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:

dart
print(1_500_000.bytes.toCoarsest()); // 1.5 MB
print(1_048_576.bytes.toCoarsest()); // 1.0 MB  (metric — not MiB)
Implementation
dart
&#47;&#47; 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 &#47; divider >= 1) {
        return loop(value &#47; divider, coarser);
      } else if (unit == this.unit) {
        return this;
      } else {
        return Information(value, unit);
      }
    }

    return switch (unit) {
      &#47;&#47; 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()),
      &#47;&#47; 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()),
      &#47;&#47; 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()),
      &#47;&#47; 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

StringtoString()

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
dart
@override
String toString() => '$value ${unit.symbol}';

Operators

operator +() inherited

Informationoperator +(Informationthat)

Returns the sum of this quantity and that, expressed in unit.

that is converted to unit before adding, so mixed-unit addition is safe.

Inherited from Quantity.

Implementation
dart
A operator +(A that) => unit.call(value + that.to(unit));

operator -() inherited

Informationoperator -(Informationthat)

Returns the difference of this quantity and that, expressed in unit.

that is converted to unit before subtracting, so mixed-unit subtraction is safe.

Inherited from Quantity.

Implementation
dart
A operator -(A that) => unit.call(value - that.to(unit));

operator <() inherited

booloperator <(Informationthat)

Returns true if this quantity is less than that.

that is converted to unit before comparing.

Inherited from Quantity.

Implementation
dart
bool operator <(A that) => value < that.to(unit);

operator <=() inherited

booloperator <=(Informationthat)

Returns true if this quantity is less than or equal to that.

that is converted to unit before comparing.

Inherited from Quantity.

Implementation
dart
bool operator <=(A that) => value <= that.to(unit);

operator ==() inherited

booloperator ==(Objectother)

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 == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must 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
dart
@override
bool operator ==(Object other) =>
    identical(this, other) ||
    (other is Quantity<A> && other.value == value && other.unit == unit);

operator >() inherited

booloperator >(Informationthat)

Returns true if this quantity is greater than that.

that is converted to unit before comparing.

Inherited from Quantity.

Implementation
dart
bool operator >(A that) => value > that.to(unit);

operator >=() inherited

booloperator >=(Informationthat)

Returns true if this quantity is greater than or equal to that.

that is converted to unit before comparing.

Inherited from Quantity.

Implementation
dart
bool operator >=(A that) => value >= that.to(unit);

Static Properties

units final

finalSet<InformationUnit>units

All supported Information units.

Implementation
dart
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(Strings)

Parses s into an Information, returning None if parsing fails.

Implementation
dart
static Option<Information> parse(String s) => Quantity.parse(s, units);

Constants

bits

constBitsbits

Unit for bits (bit) — 1/8 of a byte.

Implementation
dart
static const bits = Bits._();

BitsConversionFactor

constdoubleBitsConversionFactor

Conversion factor from bytes to bits: 1 byte = 8 bits, so 1 bit = 0.125 bytes.

Implementation
dart
static const BitsConversionFactor = 0.125;

bytes

constBytesbytes

Unit for bytes (B) — the SI base unit of information.

Implementation
dart
static const bytes = Bytes._();

exabits

constExabitsexabits

Unit for exabits (Ebit) — 10¹⁸ bits.

Implementation
dart
static const exabits = Exabits._();

exabytes

constExabytesexabytes

Unit for exabytes (EB) — 10¹⁸ bytes.

Implementation
dart
static const exabytes = Exabytes._();

exbibits

constExbibitsexbibits

Unit for exbibits (Eibit) — 2⁶⁰ bits.

Implementation
dart
static const exbibits = Exbibits._();

exbibytes

constExbibytesexbibytes

Unit for exbibytes (EiB) — 2⁶⁰ bytes.

Implementation
dart
static const exbibytes = Exbibytes._();

gibibits

constGibibitsgibibits

Unit for gibibits (Gibit) — 2³⁰ bits.

Implementation
dart
static const gibibits = Gibibits._();

gibibytes

constGibibytesgibibytes

Unit for gibibytes (GiB) — 2³⁰ bytes.

Implementation
dart
static const gibibytes = Gibibytes._();

gigabits

constGigabitsgigabits

Unit for gigabits (Gbit) — 10⁹ bits.

Implementation
dart
static const gigabits = Gigabits._();

gigabytes

constGigabytesgigabytes

Unit for gigabytes (GB) — 10⁹ bytes.

Implementation
dart
static const gigabytes = Gigabytes._();

kibibits

constKibibitskibibits

Unit for kibibits (Kibit) — 2¹⁰ bits.

Implementation
dart
static const kibibits = Kibibits._();

kibibytes

constKibibyteskibibytes

Unit for kibibytes (KiB) — 2¹⁰ = 1 024 bytes.

Implementation
dart
static const kibibytes = Kibibytes._();

kilobits

constKilobitskilobits

Unit for kilobits (Kbit) — 10³ bits.

Implementation
dart
static const kilobits = Kilobits._();

kilobytes

constKilobyteskilobytes

Unit for kilobytes (KB) — 10³ bytes.

Implementation
dart
static const kilobytes = Kilobytes._();

mebibits

constMebibitsmebibits

Unit for mebibits (Mibit) — 2²⁰ bits.

Implementation
dart
static const mebibits = Mebibits._();

mebibytes

constMebibytesmebibytes

Unit for mebibytes (MiB) — 2²⁰ = 1 048 576 bytes.

Implementation
dart
static const mebibytes = Mebibytes._();

megabits

constMegabitsmegabits

Unit for megabits (Mbit) — 10⁶ bits.

Implementation
dart
static const megabits = Megabits._();

megabytes

constMegabytesmegabytes

Unit for megabytes (MB) — 10⁶ bytes.

Implementation
dart
static const megabytes = Megabytes._();

octets

constOctetsoctets

Unit for octets (o) — equivalent to bytes; common in networking contexts.

Implementation
dart
static const octets = Octets._();

pebibits

constPebibitspebibits

Unit for pebibits (Pibit) — 2⁵⁰ bits.

Implementation
dart
static const pebibits = Pebibits._();

pebibytes

constPebibytespebibytes

Unit for pebibytes (PiB) — 2⁵⁰ bytes.

Implementation
dart
static const pebibytes = Pebibytes._();

petabits

constPetabitspetabits

Unit for petabits (Pbit) — 10¹⁵ bits.

Implementation
dart
static const petabits = Petabits._();

petabytes

constPetabytespetabytes

Unit for petabytes (PB) — 10¹⁵ bytes.

Implementation
dart
static const petabytes = Petabytes._();

tebibits

constTebibitstebibits

Unit for tebibits (Tibit) — 2⁴⁰ bits.

Implementation
dart
static const tebibits = Tebibits._();

tebibytes

constTebibytestebibytes

Unit for tebibytes (TiB) — 2⁴⁰ bytes.

Implementation
dart
static const tebibytes = Tebibytes._();

terabits

constTerabitsterabits

Unit for terabits (Tbit) — 10¹² bits.

Implementation
dart
static const terabits = Terabits._();

terabytes

constTerabytesterabytes

Unit for terabytes (TB) — 10¹² bytes.

Implementation
dart
static const terabytes = Terabytes._();

yobibits

constYobibitsyobibits

Unit for yobibits (Yibit) — 2⁸⁰ bits.

Implementation
dart
static const yobibits = Yobibits._();

yobibytes

constYobibytesyobibytes

Unit for yobibytes (YiB) — 2⁸⁰ bytes.

Implementation
dart
static const yobibytes = Yobibytes._();

yottabits

constYottabitsyottabits

Unit for yottabits (Ybit) — 10²⁴ bits.

Implementation
dart
static const yottabits = Yottabits._();

yottabytes

constYottabytesyottabytes

Unit for yottabytes (YB) — 10²⁴ bytes.

Implementation
dart
static const yottabytes = Yottabytes._();

zebibits

constZebibitszebibits

Unit for zebibits (Zibit) — 2⁷⁰ bits.

Implementation
dart
static const zebibits = Zebibits._();

zebibytes

constZebibyteszebibytes

Unit for zebibytes (ZiB) — 2⁷⁰ bytes.

Implementation
dart
static const zebibytes = Zebibytes._();

zettabits

constZettabitszettabits

Unit for zettabits (Zbit) — 10²¹ bits.

Implementation
dart
static const zettabits = Zettabits._();

zettabytes

constZettabyteszettabytes

Unit for zettabytes (ZB) — 10²¹ bytes.

Implementation
dart
static const zettabytes = Zettabytes._();