\Drupal\strata\Plugin\views\field Bytes

Renders a byte count in the largest unit that stays readable.

Every size in Strata is a byte count and most of them are large. A raw 4194304 in a table cell is a number an operator has to decode; 4.0 MiB is one they can compare at a glance, which is the whole job of a report.

Binary units, because these are stored bytes and every tool an operator will check them against - du, ls, the object store's own console - uses binary too. Provider billing uses decimal gigabytes and the estimator converts there; a table of stored sizes is not a bill.

Summary

Methods
Properties
Constants
buildOptionsForm
render
format
No public properties found
UNITS
defineOptions
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Constant

UNITS

UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']

The units, largest last.

Methods

buildOptionsForm()

buildOptionsForm(array  $form, \Drupal\Core\Form\FormStateInterface  $form_state) : void

{@inheritdoc}

Parameters

array $form

The form.

\Drupal\Core\Form\FormStateInterface $form_state

The form state.

Returns

void —

render()

render(\Drupal\views\ResultRow  $values) : string

{@inheritdoc}

Parameters

\Drupal\views\ResultRow $values

The row.

Returns

string —

The rendered value.

format()

format(int  $bytes, int  $precision = 1) : string

A byte count in the largest unit that stays readable.

Parameters

int $bytes

The count.

int $precision

Decimal places for everything above bytes.

Returns

string —

Something such as "4.0 MiB".

defineOptions()

defineOptions() : array<string,mixed>

{@inheritdoc}

Returns

array

The option definitions.