Skip to content

Commit

Permalink
fix(OC_Helper): Use correct binary notation for calculating humand fi…
Browse files Browse the repository at this point in the history
…le sizes

Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Sep 3, 2024
1 parent 6b85a3a commit 55e5dc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OC_Helper {
* @param int|float $bytes file size in bytes
* @return string a human readable file size
*
* Makes 2048 to 2 kB.
* Makes 2048 to 2 KiB.
*/
public static function humanFileSize(int|float $bytes): string {
if ($bytes < 0) {
Expand All @@ -51,23 +51,23 @@ public static function humanFileSize(int|float $bytes): string {
}
$bytes = round($bytes / 1024, 0);
if ($bytes < 1024) {
return "$bytes KB";
return "$bytes KiB";
}
$bytes = round($bytes / 1024, 1);
if ($bytes < 1024) {
return "$bytes MB";
return "$bytes MiB";
}
$bytes = round($bytes / 1024, 1);
if ($bytes < 1024) {
return "$bytes GB";
return "$bytes GiB";
}
$bytes = round($bytes / 1024, 1);
if ($bytes < 1024) {
return "$bytes TB";
return "$bytes TiB";
}

$bytes = round($bytes / 1024, 1);
return "$bytes PB";
return "$bytes PiB";
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/LegacyHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public function testHumanFileSize($expected, $input) {
public function humanFileSizeProvider() {
return [
['0 B', 0],
['1 KB', 1024],
['9.5 MB', 10000000],
['1.3 GB', 1395864371],
['465.7 GB', 500000000000],
['454.7 TB', 500000000000000],
['444.1 PB', 500000000000000000],
['1 KiB', 1024],
['9.5 MiB', 10000000],
['1.3 GiB', 1395864371],
['465.7 GiB', 500000000000],
['454.7 TiB', 500000000000000],
['444.1 PiB', 500000000000000000],
];
}

Expand Down

0 comments on commit 55e5dc0

Please sign in to comment.