mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-08 15:56:23 +02:00
Add download speed to NetworkSocket
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
namespace HyperbolicDownloaderApi.Utilities;
|
||||
internal static class UnitFormatter
|
||||
{
|
||||
public static string TransferRate(long bytesPerSecond)
|
||||
{
|
||||
string[] ordinals = new[] { "", "K", "M", "G", "T", "P", "E" };
|
||||
|
||||
decimal rate = bytesPerSecond * 8;
|
||||
|
||||
int ordinal = 0;
|
||||
|
||||
while (rate > 1000)
|
||||
{
|
||||
rate /= 1000;
|
||||
ordinal++;
|
||||
}
|
||||
|
||||
return $"{Math.Round(rate, 0, MidpointRounding.AwayFromZero)}{ordinals[ordinal]}bps";
|
||||
}
|
||||
|
||||
public static string FileSize(long bytes)
|
||||
{
|
||||
string[] ordinals = new[] { "", "K", "M", "G", "T", "P", "E" };
|
||||
|
||||
decimal rate = bytes;
|
||||
|
||||
int ordinal = 0;
|
||||
|
||||
while (rate > 1000)
|
||||
{
|
||||
rate /= 1000;
|
||||
ordinal++;
|
||||
}
|
||||
|
||||
return $"{Math.Round(rate, 0, MidpointRounding.AwayFromZero)}{ordinals[ordinal]}B";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user