Add transfer logging output (#77)
Co-authored-by: Dane Everitt <dane@daneeveritt.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user