MCPcopy
hub / github.com/ChineseSubFinder/ChineseSubFinder / GetFileSHA1String

Function GetFileSHA1String

pkg/util.go:637–657  ·  view source on GitHub ↗

GetFileSHA1String 获取文件的 SHA1 字符串

(fileFPath string)

Source from the content-addressed store, hash-verified

635
636// GetFileSHA1String 获取文件的 SHA1 字符串
637func GetFileSHA1String(fileFPath string) (string, error) {
638 h := sha1.New()
639
640 fp, err := os.Open(fileFPath)
641 if err != nil {
642 return "", err
643 }
644 defer func() {
645 _ = fp.Close()
646 }()
647
648 partAll, err := io.ReadAll(fp)
649 if err != nil {
650 return "", err
651 }
652
653 h.Write(partAll)
654 hashBytes := h.Sum(nil)
655
656 return fmt.Sprintf("%x", md5.Sum(hashBytes)), nil
657}
658
659// GetFileSHA256String 获取文件的 SHA256 字符串
660func GetFileSHA256String(fileFPath string) (string, error) {

Callers

nothing calls this directly

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected