Skip to content

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

Properties

hashCode no setter inherited

int get hashCode

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

Type get runtimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
dart
external Type get runtimeType;

toBits no setter

Information get toBits

Converts this to bits (bit).

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

toBytes no setter

Information get toBytes

Converts this to bytes (B).

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

toExabits no setter

Information get toExabits

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

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

toExabytes no setter

Information get toExabytes

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

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

toExbibits no setter

Information get toExbibits

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

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

toExbibytes no setter

Information get toExbibytes

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

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

toGibibits no setter

Information get toGibibits

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

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

toGibibytes no setter

Information get toGibibytes

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

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

toGigabits no setter

Information get toGigabits

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

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

toGigabytes no setter

Information get toGigabytes

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

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

toKibibits no setter

Information get toKibibits

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

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

toKibibytes no setter

Information get toKibibytes

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

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

toKilobits no setter

Information get toKilobits

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

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

toKilobytes no setter

Information get toKilobytes

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

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

toMebibits no setter

Information get toMebibits

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

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

toMebibytes no setter

Information get toMebibytes

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

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

toMegabits no setter

Information get toMegabits

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

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

toMegabytes no setter

Information get toMegabytes

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

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

toOctets no setter

Information get toOctets

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

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

toPebibits no setter

Information get toPebibits

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

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

toPebibytes no setter

Information get toPebibytes

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

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

toPetabits no setter

Information get toPetabits

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

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

toPetabytes no setter

Information get toPetabytes

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

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

toTebibits no setter

Information get toTebibits

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

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

toTebibytes no setter

Information get toTebibytes

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

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

toTerabits no setter

Information get toTerabits

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

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

toTerabytes no setter

Information get toTerabytes

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

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

toYobibits no setter

Information get toYobibits

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

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

toYobibytes no setter

Information get toYobibytes

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

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

toYottabits no setter

Information get toYottabits

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

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

toYottabytes no setter

Information get toYottabytes

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

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

toZebibits no setter

Information get toZebibits

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

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

toZebibytes no setter

Information get toZebibytes

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

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

toZettabits no setter

Information get toZettabits

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

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

toZettabytes no setter

Information get toZettabytes

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

final double value

The raw numeric value of this quantity expressed in unit.

Inherited from Quantity.

Implementation
dart
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
dart
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:

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

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

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

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
dart
@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
dart
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
dart
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
dart
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
dart
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 == 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

bool operator >(Information that)

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

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
dart
bool operator >=(A that) => value >= that.to(unit);

Static Properties

units final

final Set<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(String s)

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

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

Constants

bits

const Bits bits

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

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

BitsConversionFactor

const double BitsConversionFactor

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

Implementation
dart
static const BitsConversionFactor = 0.125;

bytes

const Bytes bytes

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

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

exabits

const Exabits exabits

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

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

exabytes

const Exabytes exabytes

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

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

exbibits

const Exbibits exbibits

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

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

exbibytes

const Exbibytes exbibytes

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

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

gibibits

const Gibibits gibibits

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

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

gibibytes

const Gibibytes gibibytes

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

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

gigabits

const Gigabits gigabits

Unit for gigabits (Gbit) — 10⁹ bits.

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

gigabytes

const Gigabytes gigabytes

Unit for gigabytes (GB) — 10⁹ bytes.

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

kibibits

const Kibibits kibibits

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

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

kibibytes

const Kibibytes kibibytes

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

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

kilobits

const Kilobits kilobits

Unit for kilobits (Kbit) — 10³ bits.

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

kilobytes

const Kilobytes kilobytes

Unit for kilobytes (KB) — 10³ bytes.

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

mebibits

const Mebibits mebibits

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

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

mebibytes

const Mebibytes mebibytes

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

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

megabits

const Megabits megabits

Unit for megabits (Mbit) — 10⁶ bits.

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

megabytes

const Megabytes megabytes

Unit for megabytes (MB) — 10⁶ bytes.

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

octets

const Octets octets

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

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

pebibits

const Pebibits pebibits

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

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

pebibytes

const Pebibytes pebibytes

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

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

petabits

const Petabits petabits

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

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

petabytes

const Petabytes petabytes

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

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

tebibits

const Tebibits tebibits

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

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

tebibytes

const Tebibytes tebibytes

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

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

terabits

const Terabits terabits

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

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

terabytes

const Terabytes terabytes

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

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

yobibits

const Yobibits yobibits

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

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

yobibytes

const Yobibytes yobibytes

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

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

yottabits

const Yottabits yottabits

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

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

yottabytes

const Yottabytes yottabytes

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

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

zebibits

const Zebibits zebibits

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

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

zebibytes

const Zebibytes zebibytes

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

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

zettabits

const Zettabits zettabits

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

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

zettabytes

const Zettabytes zettabytes

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

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