@@ -177,13 +177,14 @@ func (s *Server) PingAndJitter(count int) (float64, float64, error) {
177177}
178178
179179// Download performs the actual download test
180- func (s * Server ) Download (silent bool , useBytes bool ) (float64 , int , error ) {
180+ func (s * Server ) Download (silent bool , useBytes , useMebi bool ) (float64 , int , error ) {
181181 t := time .Now ()
182182 defer func () {
183183 s .TLog .Logf ("Download took %s" , time .Now ().Sub (t ).String ())
184184 }()
185185
186186 counter := & BytesCounter {}
187+ counter .SetMebi (useMebi )
187188
188189 ctx , cancel := context .WithCancel (context .Background ())
189190 defer cancel ()
@@ -233,7 +234,7 @@ func (s *Server) Download(silent bool, useBytes bool) (float64, int, error) {
233234 if useBytes {
234235 s .Suffix = fmt .Sprintf (" %s" , counter .AvgHumanize ())
235236 } else {
236- s .Suffix = fmt .Sprintf (" %s " , counter .AvgMbits ())
237+ s .Suffix = fmt .Sprintf (" %.2f Mbps " , counter .AvgMbps ())
237238 }
238239 }
239240
@@ -242,7 +243,7 @@ func (s *Server) Download(silent bool, useBytes bool) (float64, int, error) {
242243 if useBytes {
243244 pb .FinalMSG = fmt .Sprintf ("Download rate:\t %s\n " , counter .AvgHumanize ())
244245 } else {
245- pb .FinalMSG = fmt .Sprintf ("Download rate:\t %s \n " , counter .AvgMbits ())
246+ pb .FinalMSG = fmt .Sprintf ("Download rate:\t %.2f Mbps \n " , counter .AvgMbps ())
246247 }
247248 pb .Stop ()
248249 }()
@@ -261,17 +262,18 @@ Loop:
261262 }
262263 }
263264
264- return counter .Average () / 131072 , counter .Total (), nil
265+ return counter .AvgMbps () , counter .Total (), nil
265266}
266267
267268// Upload performs the actual upload test
268- func (s * Server ) Upload (noPrealloc , silent , useBytes bool ) (float64 , int , error ) {
269+ func (s * Server ) Upload (noPrealloc , silent , useBytes , useMebi bool ) (float64 , int , error ) {
269270 t := time .Now ()
270271 defer func () {
271272 s .TLog .Logf ("Upload took %s" , time .Now ().Sub (t ).String ())
272273 }()
273274
274275 counter := & BytesCounter {}
276+ counter .SetMebi (useMebi )
275277
276278 if noPrealloc {
277279 log .Info ("Pre-allocation is disabled, performance might be lower!" )
@@ -322,7 +324,7 @@ func (s *Server) Upload(noPrealloc, silent, useBytes bool) (float64, int, error)
322324 if useBytes {
323325 s .Suffix = fmt .Sprintf (" %s" , counter .AvgHumanize ())
324326 } else {
325- s .Suffix = fmt .Sprintf (" %s " , counter .AvgMbits ())
327+ s .Suffix = fmt .Sprintf (" %.2f Mbps " , counter .AvgMbps ())
326328 }
327329 }
328330
@@ -331,7 +333,7 @@ func (s *Server) Upload(noPrealloc, silent, useBytes bool) (float64, int, error)
331333 if useBytes {
332334 pb .FinalMSG = fmt .Sprintf ("Upload rate:\t %s\n " , counter .AvgHumanize ())
333335 } else {
334- pb .FinalMSG = fmt .Sprintf ("Upload rate:\t %s \n " , counter .AvgMbits ())
336+ pb .FinalMSG = fmt .Sprintf ("Upload rate:\t %.2f Mbps \n " , counter .AvgMbps ())
335337 }
336338 pb .Stop ()
337339 }()
@@ -350,7 +352,7 @@ Loop:
350352 }
351353 }
352354
353- return counter .Average () / 131072 , counter .Total (), nil
355+ return counter .AvgMbps () , counter .Total (), nil
354356}
355357
356358// GetIPInfo accesses the backend's getIP.php endpoint and get current client's IP information
0 commit comments