If you'd like to output Drupal 8 Media file size (mapper field) output in human-readable format, this snippet may help you! in MYTHEME.theme file:
<?php
function MYTHEME_preprocess_media(&$variables) {
/** @var \Drupal\media_entity\MediaInterface $media */
$media = $variables['elements']['#media'];
if ($media->bundle() == 'document' && !empty($media-> field_document_size)) {
$variables['content']['field_document_size'][0]['#markup'] = format_size(\Drupal\Component\Utility\Bytes::toNumber($variables['content']['field_document_size'][0]['#markup'])); }
}
of course you can also use it similar in your custom module.