github.com/dim13/unifi@v0.0.0-20230308161331-9b04946f5e93/bytes.go (about)

     1  // Copyright (c) 2014 The unifi Authors. All rights reserved.
     2  // Use of this source code is governed by ISC-style license
     3  // that can be found in the LICENSE file.
     4  
     5  package unifi
     6  
     7  import "fmt"
     8  
     9  type Bytes float64
    10  
    11  func (b Bytes) String() string {
    12  	var i int
    13  	dim := ` kMGTPEZY`
    14  	for b > 1024 {
    15  		b /= 1024
    16  		i++
    17  	}
    18  	return fmt.Sprintf("%6.1f %sB", b, string(dim[i]))
    19  }