ruspa/real_walker.go

32 lines
509 B
Go
Raw Normal View History

2020-03-01 23:09:00 +01:00
package main
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)
}
func NewRealWalker(path string, report chan int64) *RealWalker {
r := &RealWalker{path: path, report: report}
return r
}