using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Untity
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class StreamHelper
|
{
|
private static readonly string[] _suffixes = new string[] { " B", " KB", " MB", " GB", " TB", " PB" };
|
|
/// <summary>
|
/// 获取文件大小的显示字符串
|
/// </summary>
|
private static string BytesToReadableValue(long number)
|
{
|
double last = 1;
|
for (int i = 0; i < _suffixes.Length; i++)
|
{
|
var current = Math.Pow(1024, i + 1);
|
var temp = number / current;
|
if (temp < 1)
|
{
|
return (number / last).ToString("n2") + _suffixes[i];
|
}
|
last = current;
|
}
|
return number.ToString();
|
}
|
|
/// <summary>
|
/// 获取可读尺寸
|
/// </summary>
|
public static string GetReadableSize(Stream stream)
|
{
|
return BytesToReadableValue(stream.Length);
|
}
|
|
}
|
}
|