feat: Replace cli to cobra (#1855)
* Replace cli * Replace cli * Replace cli * Format code * Add compare case * Add compare case * Add compare case * Support go style flag * Support go style flag * Add test case
This commit is contained in:
@@ -2,6 +2,8 @@ package pathx
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -283,3 +285,19 @@ func Copy(src, dest string) error {
|
||||
_, err = io.Copy(w, f)
|
||||
return err
|
||||
}
|
||||
|
||||
func Hash(file string) (string, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
hash := md5.New()
|
||||
_, err = io.Copy(hash, f)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(hash.Sum(nil)), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user