Skip to content

Commit

Permalink
Get rid of go-humanize
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed May 22, 2018
1 parent c4c412f commit 50f60be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
7 changes: 3 additions & 4 deletions htfs/cmd/htfsmonkey/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"time"

"github.com/itchio/arkive/zip"
"github.com/itchio/httpkit/progress"
"github.com/itchio/wharf/eos"
"github.com/itchio/wharf/eos/option"

humanize "github.com/dustin/go-humanize"
"github.com/pkg/errors"
)

Expand All @@ -31,7 +31,7 @@ func doZip() error {

zipBytes, err := ioutil.ReadFile(zipPath)
must(err)
log.Printf("Read %s zip file", humanize.IBytes(uint64(len(zipBytes))))
log.Printf("Read %s zip file", progress.FormatBytes(int64(len(zipBytes))))
log.Printf("Validating...")

numFiles := 0
Expand Down Expand Up @@ -95,7 +95,6 @@ func doZip() error {
for index := range indices {
func() {
zf := zr.File[index]
// log.Printf("Extracting file %d (%s)", index, humanize.IBytes(uint64(zf.UncompressedSize64)))

rc, err := zf.Open()
must(err)
Expand Down Expand Up @@ -157,7 +156,7 @@ func doZip() error {
}

log.Printf("Files extracted: %d", filesExtracted)
log.Printf("Total extracted: %s", humanize.IBytes(uint64(bytesExtracted)))
log.Printf("Total extracted: %s", progress.FormatBytes(bytesExtracted))

return nil
}
6 changes: 3 additions & 3 deletions htfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

goerrors "errors"

humanize "github.com/dustin/go-humanize"
"github.com/itchio/httpkit/neterr"
"github.com/itchio/httpkit/progress"
"github.com/itchio/httpkit/retrycontext"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -593,8 +593,8 @@ func (f *File) Close() error {
totalServedBytes := fetchedBytes
percCached = float64(f.stats.cachedBytes) / float64(totalServedBytes) * 100.0

log.Printf("= fetched: %s / %s (%.2f%%)", humanize.IBytes(uint64(fetchedBytes)), humanize.IBytes(uint64(size)), perc)
log.Printf("= served from cache: %s (%.2f%% of all served bytes)", humanize.IBytes(uint64(f.stats.cachedBytes)), percCached)
log.Printf("= fetched: %s / %s (%.2f%%)", progress.FormatBytes(fetchedBytes), progress.FormatBytes(size), perc)
log.Printf("= served from cache: %s (%.2f%% of all served bytes)", progress.FormatBytes(f.stats.cachedBytes), percCached)

totalReads := f.stats.numCacheHits + f.stats.numCacheMiss
if totalReads == 0 {
Expand Down
8 changes: 4 additions & 4 deletions uploader/chunk_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

humanize "github.com/dustin/go-humanize"
"github.com/itchio/httpkit/progress"
"github.com/itchio/httpkit/retrycontext"
"github.com/itchio/wharf/counter"
"github.com/itchio/wharf/state"
Expand Down Expand Up @@ -110,7 +110,7 @@ func (cu *chunkUploader) tryPut(buf []byte, last bool) error {

status := interpretGcsStatusCode(res.StatusCode)
if status == gcsUploadComplete && last {
cu.debugf("✓ %s upload complete!", humanize.IBytes(uint64(cu.offset+buflen)))
cu.debugf("✓ %s upload complete!", progress.FormatBytes(int64(cu.offset+buflen)))
return nil
}

Expand Down Expand Up @@ -152,10 +152,10 @@ func (cu *chunkUploader) tryPut(buf []byte, last bool) error {
}

committedBytes := committedRange.end - cu.offset
perSec := humanize.IBytes(uint64(float64(committedBytes) / callDuration.Seconds()))
perSec := progress.FormatBPS(committedBytes, callDuration)

if committedRange.end == expectedOffset {
cu.debugf("✓ Commit succeeded (%d blocks stored @ %s / s)", buflen/gcsChunkSize, perSec)
cu.debugf("✓ Commit succeeded (%d blocks stored @ %s)", buflen/gcsChunkSize, perSec)
return nil
}

Expand Down

0 comments on commit 50f60be

Please sign in to comment.