diff --git a/app/MindWork AI Studio/Tools/LongExtensions.cs b/app/MindWork AI Studio/Tools/LongExtensions.cs new file mode 100644 index 0000000..3209e47 --- /dev/null +++ b/app/MindWork AI Studio/Tools/LongExtensions.cs @@ -0,0 +1,22 @@ +namespace AIStudio.Tools; + +public static class LongExtensions +{ + /// + /// Formats the file size in a human-readable format. + /// + /// The size in bytes. + /// The formatted file size. + public static string FileSize(this long sizeBytes) + { + string[] sizes = { "B", "kB", "MB", "GB", "TB" }; + var order = 0; + while (sizeBytes >= 1024 && order < sizes.Length - 1) + { + order++; + sizeBytes /= 1024; + } + + return $"{sizeBytes:0.##} {sizes[order]}"; + } +} \ No newline at end of file