Browse Source

Sort output before it goes out

Fixes #1
recursive
Stephen McQuay 5 years ago
parent
commit
98d5dd7033
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
  1. 22
      hash.go

22
hash.go

@ -9,6 +9,7 @@ import (
"hash"
"io"
"os"
"sort"
"sync"
)
@ -19,6 +20,13 @@ type result struct {
err error
}
// results exists to sort a slice of result
type results []result
func (r results) Len() int { return len(r) }
func (r results) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r results) Less(i, j int) bool { return r[i].f < r[j].f }
// hashr exists so that we can make a thing that can return valid hash.Hash
// interfaces.
type hashr func() hash.Hash
@ -72,7 +80,19 @@ func hsh(files []string) chan result {
res = append(res, compute(h, jobs))
}
return rmerge(res)
o := make(chan result)
go func() {
rs := results{}
for r := range rmerge(res) {
rs = append(rs, r)
}
sort.Sort(rs)
for _, r := range rs {
o <- r
}
close(o)
}()
return o
}
// compute is the checksumming workhorse

Loading…
Cancel
Save