Skip to content

Commit

Permalink
progress bars
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jul 19, 2022
1 parent 13a0891 commit 578acb0
Show file tree
Hide file tree
Showing 336 changed files with 161,829 additions and 168 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ module github.com/boyter/hashit
go 1.17

require (
github.com/gosuri/uiprogress v0.0.1
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/spf13/cobra v0.0.3
github.com/zeebo/blake3 v0.2.1
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
)

require (
github.com/gosuri/uilive v0.0.4 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/spf13/pflag v1.0.3 // indirect
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
github.com/gosuri/uilive v0.0.4 h1:hUEBpQDj8D8jXgtCdBu7sWsy5sbW/5GhuO8KBwJ2jyY=
github.com/gosuri/uilive v0.0.4/go.mod h1:V/epo5LjjlDE5RJUcqx8dbw+zc93y5Ya3yg8tfZ74VI=
github.com/gosuri/uiprogress v0.0.1 h1:0kpv/XY/qTmFWl/SkaJykZXrBBzwwadmW8fRb7RJSxw=
github.com/gosuri/uiprogress v0.0.1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
Expand All @@ -20,4 +26,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc h1:HVFDs9bKvTxP6bh1Rj9MCSo+UmafQtI8ZWDPVwVk9g4=
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ func main() {
false,
"verbose output",
)
flags.BoolVarP(
&processor.Progress,
"progress",
"p",
false,
"display progress of files",
)
flags.BoolVar(
&processor.Debug,
"debug",
Expand Down
8 changes: 8 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processor

import (
"fmt"
"github.com/gosuri/uiprogress"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -22,6 +23,9 @@ var Debug = false
// Trace enables trace logging output which is extremely verbose
var Trace = false

// Progress uses ui bar to display the progress of files
var Progress = false

// Recursive to walk directories
var Recursive = false

Expand Down Expand Up @@ -145,6 +149,10 @@ func Process() {
close(fileListQueue)
}()

if Progress {
uiprogress.Start() // start rendering of progress bars
}

var wg sync.WaitGroup
for i := 0; i < runtime.NumCPU(); i++ {
wg.Add(1)
Expand Down
21 changes: 19 additions & 2 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
"crypto/sha512"
"encoding/hex"
"fmt"
"github.com/gosuri/uiprogress"
"github.com/minio/blake2b-simd"
"github.com/zeebo/blake3"
"golang.org/x/crypto/md4"
"golang.org/x/crypto/sha3"
"io"
"log"
"os"
"strings"
"sync"
)

Expand Down Expand Up @@ -49,7 +51,7 @@ func fileProcessorWorker(input chan string, output chan Result) {
}

fileStartTime := makeTimestampMilli()
r, err := processScanner(res)
r, err := processScanner(res, int(fsize))
if Trace {
printTrace(fmt.Sprintf("milliseconds processMemoryMap: %s: %d", res, makeTimestampMilli()-fileStartTime))
}
Expand Down Expand Up @@ -98,7 +100,7 @@ func fileProcessorWorker(input chan string, output chan Result) {

// TODO compare this to memory maps
// Random tests indicate that mmap is faster when not in power save mode
func processScanner(filename string) (Result, error) {
func processScanner(filename string, fsize int) (Result, error) {
file, err := os.Open(filename)
if err != nil {
printError(fmt.Sprintf("opening file %s: %s", filename, err.Error()))
Expand Down Expand Up @@ -251,6 +253,16 @@ func processScanner(filename string) (Result, error) {
}()
}

var bar *uiprogress.Bar
if Progress {
bar = uiprogress.AddBar(fsize) // Add a new bar
bar.AppendFunc(func(b *uiprogress.Bar) string {
split := strings.Split(filename, "/")
return "file: " + split[len(split)-1]
})
}

sum := 0
data := make([]byte, 4_194_304)
for {
n, err := file.Read(data)
Expand All @@ -259,6 +271,11 @@ func processScanner(filename string) (Result, error) {
return Result{}, err
}

if Progress {
sum += n
_ = bar.Set(sum)
}

// Need to make a copy here as it can be modified before
// the goroutine processes it in the channel
tmp := make([]byte, len(data))
Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/gosuri/uilive/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/gosuri/uilive/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/gosuri/uilive/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/github.com/gosuri/uilive/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/gosuri/uilive/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/gosuri/uilive/terminal_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/gosuri/uilive/terminal_size_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 578acb0

Please sign in to comment.