aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/fs/hash.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
commitfc8c5fdce62fb229202659408798a7b6c98f6e8b (patch)
tree7554f80e50de4af6fd255afa7c21bcdd58a7af34 /cli/internal/fs/hash.go
parentdd84b9d64fb98746a230cd24233ff50a562c39c9 (diff)
downloadHydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.tar.gz
HydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.zip
Diffstat (limited to 'cli/internal/fs/hash.go')
-rw-r--r--cli/internal/fs/hash.go61
1 files changed, 0 insertions, 61 deletions
diff --git a/cli/internal/fs/hash.go b/cli/internal/fs/hash.go
deleted file mode 100644
index fed7d87..0000000
--- a/cli/internal/fs/hash.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package fs
-
-import (
- "crypto/sha1"
- "encoding/hex"
- "fmt"
- "io"
- "os"
- "strconv"
-
- "github.com/vercel/turbo/cli/internal/xxhash"
-)
-
-func HashObject(i interface{}) (string, error) {
- hash := xxhash.New()
-
- _, err := hash.Write([]byte(fmt.Sprintf("%v", i)))
-
- return hex.EncodeToString(hash.Sum(nil)), err
-}
-
-func HashFile(filePath string) (string, error) {
- file, err := os.Open(filePath)
- if err != nil {
- return "", err
- }
- defer file.Close()
-
- hash := xxhash.New()
- if _, err := io.Copy(hash, file); err != nil {
- return "", err
- }
-
- return hex.EncodeToString(hash.Sum(nil)), nil
-}
-
-// GitLikeHashFile is a function that mimics how Git
-// calculates the SHA1 for a file (or, in Git terms, a "blob") (without git)
-func GitLikeHashFile(filePath string) (string, error) {
- file, err := os.Open(filePath)
- if err != nil {
- return "", err
- }
- defer file.Close()
-
- stat, err := file.Stat()
- if err != nil {
- return "", err
- }
- hash := sha1.New()
- hash.Write([]byte("blob"))
- hash.Write([]byte(" "))
- hash.Write([]byte(strconv.FormatInt(stat.Size(), 10)))
- hash.Write([]byte{0})
-
- if _, err := io.Copy(hash, file); err != nil {
- return "", err
- }
-
- return hex.EncodeToString(hash.Sum(nil)), nil
-}