Skip to content

Commit 55e5dc0

Browse files
committed
fix(OC_Helper): Use correct binary notation for calculating humand file sizes
Signed-off-by: provokateurin <[email protected]>
1 parent 6b85a3a commit 55e5dc0

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

lib/private/legacy/OC_Helper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class OC_Helper {
4040
* @param int|float $bytes file size in bytes
4141
* @return string a human readable file size
4242
*
43-
* Makes 2048 to 2 kB.
43+
* Makes 2048 to 2 KiB.
4444
*/
4545
public static function humanFileSize(int|float $bytes): string {
4646
if ($bytes < 0) {
@@ -51,23 +51,23 @@ public static function humanFileSize(int|float $bytes): string {
5151
}
5252
$bytes = round($bytes / 1024, 0);
5353
if ($bytes < 1024) {
54-
return "$bytes KB";
54+
return "$bytes KiB";
5555
}
5656
$bytes = round($bytes / 1024, 1);
5757
if ($bytes < 1024) {
58-
return "$bytes MB";
58+
return "$bytes MiB";
5959
}
6060
$bytes = round($bytes / 1024, 1);
6161
if ($bytes < 1024) {
62-
return "$bytes GB";
62+
return "$bytes GiB";
6363
}
6464
$bytes = round($bytes / 1024, 1);
6565
if ($bytes < 1024) {
66-
return "$bytes TB";
66+
return "$bytes TiB";
6767
}
6868

6969
$bytes = round($bytes / 1024, 1);
70-
return "$bytes PB";
70+
return "$bytes PiB";
7171
}
7272

7373
/**

tests/lib/LegacyHelperTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public function testHumanFileSize($expected, $input) {
3434
public function humanFileSizeProvider() {
3535
return [
3636
['0 B', 0],
37-
['1 KB', 1024],
38-
['9.5 MB', 10000000],
39-
['1.3 GB', 1395864371],
40-
['465.7 GB', 500000000000],
41-
['454.7 TB', 500000000000000],
42-
['444.1 PB', 500000000000000000],
37+
['1 KiB', 1024],
38+
['9.5 MiB', 10000000],
39+
['1.3 GiB', 1395864371],
40+
['465.7 GiB', 500000000000],
41+
['454.7 TiB', 500000000000000],
42+
['444.1 PiB', 500000000000000000],
4343
];
4444
}
4545

0 commit comments

Comments
 (0)