1
1
Fork 0

Check for inf values before try to converts bytes to binary prefix strings

This commit is contained in:
Marek Bachmann 2022-11-30 04:35:18 +01:00
parent 037e181f82
commit 75b01f669a

View file

@ -220,6 +220,11 @@ class Strings
*/ */
public static function formatBytes(int $bytes, int $precision = 2): string public static function formatBytes(int $bytes, int $precision = 2): string
{ {
// If this method is called for an infinite (== unlimited) amount of bytes:
if ($bytes == INF) {
return INF;
}
$units = ['B', 'KB', 'MB', 'GB', 'TB']; $units = ['B', 'KB', 'MB', 'GB', 'TB'];
$bytes = max($bytes, 0); $bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = floor(($bytes ? log($bytes) : 0) / log(1024));