mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-16 21:31:45 +02:00
.config
.run
.workdir
Agent
Common
Docker
Server
Utils
Phantom.Utils.Collections
Phantom.Utils.Collections.Tests
Phantom.Utils.Cryptography
Phantom.Utils.Events
Phantom.Utils.IO
Chmod.cs
Directories.cs
FileSize.cs
Files.cs
Paths.cs
Phantom.Utils.IO.csproj
StreamCopier.cs
Phantom.Utils.Rpc
Phantom.Utils.Runtime
Phantom.Utils.Runtime.Tests
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
21 lines
575 B
C#
21 lines
575 B
C#
namespace Phantom.Utils.IO;
|
|
|
|
public readonly record struct FileSize(ulong Bytes) {
|
|
private const int Scale = 1024;
|
|
|
|
private static readonly string[] Units = {
|
|
"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"
|
|
};
|
|
|
|
public string ToHumanReadable(int decimalPlaces) {
|
|
int power = Bytes == 0L ? 0 : (int) Math.Log(Bytes, Scale);
|
|
int unit = power >= Units.Length ? Units.Length - 1 : power;
|
|
if (unit == 0) {
|
|
return Bytes + " B";
|
|
}
|
|
|
|
string format = "{0:n" + decimalPlaces + "} {1}";
|
|
return string.Format(format, Bytes / Math.Pow(Scale, unit), Units[unit]);
|
|
}
|
|
}
|