Add transfer logging output (#77)

Co-authored-by: Dane Everitt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner
2020-12-25 14:32:41 -07:00
committed by GitHub
parent 901ab1157d
commit 5c78cb9ab3
16 changed files with 398 additions and 227 deletions

View File

@@ -2,6 +2,7 @@ package system
import (
"context"
"fmt"
"sync"
"sync/atomic"
"time"
@@ -23,6 +24,18 @@ func Every(ctx context.Context, d time.Duration, work func(t time.Time)) {
}()
}
func FormatBytes(b int64) string {
if b < 1024 {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(1024), 0
for n := b / 1024; n >= 1024; n /= 1024 {
div *= 1024
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
}
type AtomicBool struct {
flag uint32
}