function drush_format_size

8.0.x drush.inc drush_format_size($size)
6.x drush.inc drush_format_size($size, $langcode = NULL)
7.x drush.inc drush_format_size($size, $langcode = NULL)
3.x drush.inc drush_format_size($size, $langcode = NULL)
4.x drush.inc drush_format_size($size, $langcode = NULL)
5.x drush.inc drush_format_size($size, $langcode = NULL)
master drush.inc drush_format_size($size)

Related topics

2 calls to drush_format_size()
_drush_bootstrap_and_dispatch in ./drush.php
_drush_print_log in includes/drush.inc
Display the log message

File

includes/drush.inc, line 1683
The drush API implementation and helpers.

Code

function drush_format_size($size, $langcode = NULL) {
  if ($size < DRUSH_DRUPAL_KILOBYTE) {
    // format_plural() not always available.
    return dt('@count bytes', array('@count' => $size));
  }
  else {
    $size = $size / DRUSH_DRUPAL_KILOBYTE; // Convert bytes to kilobytes.
    $units = array(
      dt('@size KB', array(), array('langcode' => $langcode)),
      dt('@size MB', array(), array('langcode' => $langcode)),
      dt('@size GB', array(), array('langcode' => $langcode)),
      dt('@size TB', array(), array('langcode' => $langcode)),
      dt('@size PB', array(), array('langcode' => $langcode)),
      dt('@size EB', array(), array('langcode' => $langcode)),
      dt('@size ZB', array(), array('langcode' => $langcode)),
      dt('@size YB', array(), array('langcode' => $langcode)),
    );
    foreach ($units as $unit) {
      if (round($size, 2) >= DRUSH_DRUPAL_KILOBYTE) {
        $size = $size / DRUSH_DRUPAL_KILOBYTE;
      }
      else {
        break;
      }
    }
    return str_replace('@size', round($size, 2), $unit);
  }
}