@@ -20,26 +20,13 @@ const GIB: u64 = 1024 * 1024 * 1024;
2020const MIB : u64 = 1024 * 1024 ;
2121const KIB : u64 = 1024 ;
2222
23- const EIBM1 : u64 = EIB - 1 ;
24- const PIBM1 : u64 = PIB - 1 ;
25- const TIBM1 : u64 = TIB - 1 ;
26- const GIBM1 : u64 = GIB - 1 ;
27- const MIBM1 : u64 = MIB - 1 ;
28- //const KIBM1: u64 = KIB - 1;
29-
3023const EB : u64 = 1000 * 1000 * 1000 * 1000 * 1000 * 1000 ;
3124const PB : u64 = 1000 * 1000 * 1000 * 1000 * 1000 ;
3225const TB : u64 = 1000 * 1000 * 1000 * 1000 ;
3326const GB : u64 = 1000 * 1000 * 1000 ;
3427const MB : u64 = 1000 * 1000 ;
3528const KB : u64 = 1000 ;
3629
37- const EBM1 : u64 = EB - 1 ;
38- const PBM1 : u64 = PB - 1 ;
39- const TBM1 : u64 = TB - 1 ;
40- const GBM1 : u64 = GB - 1 ;
41- const MBM1 : u64 = MB - 1 ;
42-
4330pub fn prettybytes ( count : u64 , binary : bool , decimal : bool , bytes : bool ) -> String {
4431 let mut ret = String :: new ( ) ;
4532
@@ -55,11 +42,11 @@ pub fn prettybytes(count: u64, binary: bool, decimal: bool, bytes: bool) -> Stri
5542 if binary {
5643 let _ = match count {
5744 EIB ..=u64:: MAX => write ! ( ret, "{:.4} EiB" , ( ( count / TIB ) as f64 ) / ( MIB as f64 ) ) ,
58- PIB ..= EIBM1 => write ! ( ret, "{:.4} PiB" , ( ( count / GIB ) as f64 ) / ( MIB as f64 ) ) ,
59- TIB ..= PIBM1 => write ! ( ret, "{:.4} TiB" , ( ( count / MIB ) as f64 ) / ( MIB as f64 ) ) ,
60- GIB ..= TIBM1 => write ! ( ret, "{:.2} GiB" , ( ( count / MIB ) as f64 ) / ( KIB as f64 ) ) ,
61- MIB ..= GIBM1 => write ! ( ret, "{:.1} MiB" , ( count as f64 ) / ( MIB as f64 ) ) ,
62- 0 ..= MIBM1 => write ! ( ret, "{:.1} kiB" , ( count as f64 ) / ( KIB as f64 ) ) ,
45+ PIB ..EIB => write ! ( ret, "{:.4} PiB" , ( ( count / GIB ) as f64 ) / ( MIB as f64 ) ) ,
46+ TIB ..PIB => write ! ( ret, "{:.4} TiB" , ( ( count / MIB ) as f64 ) / ( MIB as f64 ) ) ,
47+ GIB ..TIB => write ! ( ret, "{:.2} GiB" , ( ( count / MIB ) as f64 ) / ( KIB as f64 ) ) ,
48+ MIB ..GIB => write ! ( ret, "{:.1} MiB" , ( count as f64 ) / ( MIB as f64 ) ) ,
49+ 0 ..MIB => write ! ( ret, "{:.1} kiB" , ( count as f64 ) / ( KIB as f64 ) ) ,
6350 } ;
6451 }
6552
@@ -73,11 +60,11 @@ pub fn prettybytes(count: u64, binary: bool, decimal: bool, bytes: bool) -> Stri
7360 if decimal {
7461 let _ = match count {
7562 EB ..=u64:: MAX => write ! ( ret, "{:.4} EB" , ( ( count / TB ) as f64 ) / ( MB as f64 ) ) ,
76- PB ..= EBM1 => write ! ( ret, "{:.4} PB" , ( ( count / GB ) as f64 ) / ( MB as f64 ) ) ,
77- TB ..= PBM1 => write ! ( ret, "{:.4} TB" , ( ( count / MB ) as f64 ) / ( MB as f64 ) ) ,
78- GB ..= TBM1 => write ! ( ret, "{:.2} GB" , ( ( count / MB ) as f64 ) / ( KB as f64 ) ) ,
79- MB ..= GBM1 => write ! ( ret, "{:.1} MB" , ( count as f64 ) / ( MB as f64 ) ) ,
80- 0 ..= MBM1 => write ! ( ret, "{:.1} kB" , ( count as f64 ) / ( KB as f64 ) ) ,
63+ PB ..EB => write ! ( ret, "{:.4} PB" , ( ( count / GB ) as f64 ) / ( MB as f64 ) ) ,
64+ TB ..PB => write ! ( ret, "{:.4} TB" , ( ( count / MB ) as f64 ) / ( MB as f64 ) ) ,
65+ GB ..TB => write ! ( ret, "{:.2} GB" , ( ( count / MB ) as f64 ) / ( KB as f64 ) ) ,
66+ MB ..GB => write ! ( ret, "{:.1} MB" , ( count as f64 ) / ( MB as f64 ) ) ,
67+ 0 ..MB => write ! ( ret, "{:.1} kB" , ( count as f64 ) / ( KB as f64 ) ) ,
8168 } ;
8269 }
8370
0 commit comments