Skip to content

Commit

Permalink
Fixed datastorage_force_binary
Browse files Browse the repository at this point in the history
  • Loading branch information
biati-digital committed May 7, 2022
1 parent f9c9972 commit 72e9938
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions workflow/tools/datastorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public function output($result)
* Do font calculations
*
* @param array $data
* @return string
*
* @return array
*/
private function convertSize(&$data)
{
Expand All @@ -185,27 +186,33 @@ private function convertSize(&$data)
$to_base = 0;
$to_exponent = 0;
$unit = (isset($units[$to]) ? $units[$to]['unit'] : $to);
$force_binary = \Alfred\getVariable('datastorage_force_binary');

if ($from_unit == 'bit' && $to == 'b') {
if ($from_unit === 'bit' && $to === 'b') {
$result['value'] = $from * 0.125;
$result['to'] = $unit;
return $result;
}
if ($from_unit == 'b' && $to == 'bit') {
if ($from_unit === 'b' && $to === 'bit') {
$result['value'] = $from * 8;
$result['to'] = $unit;
return $result;
}

// Convert to bytes
if ($from_unit !== 'b') {

if ($force_binary === true) {
$from_base = 1024;
}

$from_exponent = (isset($units[$from_unit]) ? $units[$from_unit]['exponent'] : 0);
$from = ($from_exponent > 0 ? $from * pow($from_base, $from_exponent) : $from * $from_base);
}

$bytes = $from;

if ($to == 'b') {
if ($to === 'b') {
$result['value'] = $this->formatNumber($bytes, 8);
$result['to'] = $unit;

Expand All @@ -223,7 +230,6 @@ private function convertSize(&$data)

$to_base = $units[$to]['base'];
$to_exponent = $units[$to]['exponent'];
$force_binary = \Alfred\getVariable('datastorage_force_binary');

if ($force_binary === true) {
$to_base = 1024;
Expand Down

0 comments on commit 72e9938

Please sign in to comment.