mirror of
				https://github.com/terorie/od-database-crawler.git
				synced 2025-11-03 22:26:52 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			19 lines
		
	
	
		
			407 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			407 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package main
 | 
						|
 | 
						|
import "fmt"
 | 
						|
 | 
						|
// https://programming.guide/go/formatting-byte-size-to-human-readable-format.html
 | 
						|
func FormatByteCount(b uint64) string {
 | 
						|
	const unit = 1024
 | 
						|
	if b < unit {
 | 
						|
		return fmt.Sprintf("%d B", b)
 | 
						|
	} else {
 | 
						|
		div, exp := int64(unit), 0
 | 
						|
		for n := b / unit; n >= unit; n /= unit {
 | 
						|
			div *= unit
 | 
						|
			exp++
 | 
						|
		}
 | 
						|
		return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
 | 
						|
	}
 | 
						|
}
 |