calculate checksums
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
727 B

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "runtime"
  7. )
  8. var algo = flag.String("a", "sha256", "algorithm to use")
  9. var mode = flag.Bool("c", false, "check")
  10. var ngo = flag.Int("n", runtime.NumCPU(), "number of goroutines")
  11. var verbose = flag.Bool("v", false, "vebose")
  12. func main() {
  13. flag.Parse()
  14. files := flag.Args()
  15. switch *mode {
  16. case true:
  17. ec := 0
  18. for err := range check(files, *verbose) {
  19. ec++
  20. fmt.Fprintf(os.Stderr, "%v\n", err)
  21. }
  22. if ec > 0 {
  23. os.Exit(1)
  24. }
  25. case false:
  26. ec := 0
  27. for res := range hsh(files, *verbose) {
  28. if res.err != nil {
  29. ec++
  30. fmt.Fprintf(os.Stderr, "%v\n", res.err)
  31. } else {
  32. fmt.Printf("%v\t%v\n", res.cs, res.f)
  33. }
  34. }
  35. if ec > 0 {
  36. os.Exit(1)
  37. }
  38. }
  39. }