AutoIngest/AutoIngest/Engine/FileSize.cs

25 lines
765 B
C#

using System;
namespace AutoIngest.Engine
{
/// <summary>
/// Human-readable byte formatting — one source of truth used by the import pipeline, the
/// retention sweep, and the settings UI. Switch expression: single exit, no magic numbers
/// inline at call sites, scales from bytes to gigabytes.
/// </summary>
public static class FileSize
{
const long KB = 1024;
const long MB = 1024 * 1024;
const long GB = 1024 * 1024 * 1024;
public static string Format(long bytes) => bytes switch
{
< KB => $"{bytes} B",
< MB => $"{bytes / (double)KB:F1} KB",
< GB => $"{bytes / (double)MB:F1} MB",
_ => $"{bytes / (double)GB:F2} GB"
};
}
}