Move formatSize() to output.go
authorMikael Berthe <mikael@lilotux.net>
Sun, 14 Oct 2018 15:33:53 +0200
changeset 39 24ca1bf4a0bf
parent 38 25db238bf03f
child 40 7f9cdb9d166d
Move formatSize() to output.go
goduf.go
output.go
--- a/goduf.go	Sun Oct 14 15:23:11 2018 +0200
+++ b/goduf.go	Sun Oct 14 15:33:53 2018 +0200
@@ -447,34 +447,6 @@
 	return
 }
 
-// formatSize returns the size in a string with a human-readable format.
-func formatSize(sizeBytes uint64, short bool) string {
-	var units = map[int]string{
-		0: "B",
-		1: "KiB",
-		2: "MiB",
-		3: "GiB",
-		4: "TiB",
-		5: "PiB",
-	}
-	humanSize := sizeBytes
-	var n int
-	for n < len(units)-1 {
-		if humanSize < 10000 {
-			break
-		}
-		humanSize /= 1024
-		n++
-	}
-	if n < 1 {
-		return fmt.Sprintf("%d bytes", sizeBytes)
-	}
-	if short {
-		return fmt.Sprintf("%d %s", humanSize, units[n])
-	}
-	return fmt.Sprintf("%d bytes (%d %s)", sizeBytes, humanSize, units[n])
-}
-
 func duf(dirs []string, options Options) (Results, error) {
 	var verbose bool
 	if myLog.verbosity > 0 {
--- a/output.go	Sun Oct 14 15:23:11 2018 +0200
+++ b/output.go	Sun Oct 14 15:33:53 2018 +0200
@@ -24,6 +24,35 @@
 	"fmt"
 )
 
+// formatSize returns the size in a string with a human-readable format.
+func formatSize(sizeBytes uint64, short bool) string {
+	var units = map[int]string{
+		0: "B",
+		1: "KiB",
+		2: "MiB",
+		3: "GiB",
+		4: "TiB",
+		5: "PiB",
+	}
+	humanSize := sizeBytes
+	var n int
+	for n < len(units)-1 {
+		if humanSize < 10000 {
+			break
+		}
+		humanSize /= 1024
+		n++
+	}
+	if n < 1 {
+		return fmt.Sprintf("%d bytes", sizeBytes)
+	}
+	if short {
+		return fmt.Sprintf("%d %s", humanSize, units[n])
+	}
+	return fmt.Sprintf("%d bytes (%d %s)", sizeBytes, humanSize, units[n])
+}
+
+// displayResults formats results to plaintext or JSON and sends them to stdout
 func displayResults(results Results, jsonOutput bool, summaryOnly bool) {
 	if jsonOutput {
 		displayResultsJSON(results)