mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
38 lines
772 B
C#
38 lines
772 B
C#
using System;
|
|
|
|
namespace Robust.Shared.Utility
|
|
{
|
|
public static class ByteHelpers
|
|
{
|
|
public static string FormatKibibytes(long bytes)
|
|
{
|
|
return $"{bytes / 1024} KiB";
|
|
}
|
|
|
|
public static string FormatBytes(long bytes)
|
|
{
|
|
double d = bytes;
|
|
var i = 0;
|
|
for (; i < ByteSuffixes.Length && d >= 1024; i++)
|
|
{
|
|
d /= 1024;
|
|
}
|
|
|
|
return $"{Math.Round(d, 2)} {ByteSuffixes[i]}";
|
|
}
|
|
|
|
private static readonly string[] ByteSuffixes =
|
|
{
|
|
"B",
|
|
"KiB",
|
|
"MiB",
|
|
"GiB",
|
|
"TiB",
|
|
"PiB",
|
|
"EiB",
|
|
"ZiB",
|
|
"YiB"
|
|
};
|
|
}
|
|
}
|