ruspa/tree/real_walker.go

33 lines
526 B
Go
Raw Permalink Normal View History

package tree
2020-03-01 23:09:00 +01:00
import (
"os"
"path/filepath"
)
type RealWalker struct {
path string
report chan int64
}
func (r *RealWalker) walkFunc(path string, info os.FileInfo, err error) error {
2020-03-03 14:16:54 +01:00
if !info.IsDir() {
switch mode := info.Mode(); {
case mode.IsRegular():
r.report <- info.Size()
}
2020-03-01 23:09:00 +01:00
}
2020-03-03 14:16:54 +01:00
2020-03-01 23:09:00 +01:00
return nil
}
func (r *RealWalker) Walk() {
filepath.Walk(r.path, r.walkFunc)
2020-03-07 17:23:06 +01:00
close(r.report)
2020-03-01 23:09:00 +01:00
}
func NewRealWalker(path string, report chan int64) *RealWalker {
r := &RealWalker{path: path, report: report}
return r
}