MCPcopy Create free account
hub / github.com/LagrangeDev/LagrangeGo / ComputeBlockSha1

Function ComputeBlockSha1

utils/crypto/hash.go:76–95  ·  view source on GitHub ↗
(r io.ReadSeeker, blockSize int)

Source from the content-addressed store, hash-verified

74}
75
76func ComputeBlockSha1(r io.ReadSeeker, blockSize int) [][]byte {
77 _, _ = r.Seek(0, io.SeekStart)
78 defer func(r io.ReadSeeker, offset int64, whence int) {
79 _, _ = r.Seek(offset, whence)
80 }(r, 0, io.SeekStart)
81 result := make([][]byte, 0, 5)
82 sha1r := sha1.New()
83 buffer := make([]byte, blockSize)
84 for {
85 n, _ := io.ReadFull(r, buffer)
86 if n != blockSize {
87 sha1r.Write(buffer[:n])
88 break
89 }
90 sha1r.Write(buffer)
91 result = append(result, GetSha1Status(sha1r))
92 }
93 result = append(result, sha1r.Sum(nil))
94 return result
95}
96
97func GetSha1Status(h hash.Hash) []byte {
98 if reflect.TypeOf(h).String() != "*sha1.digest" {

Callers 2

UploadPrivateVideoMethod · 0.92
UploadGroupVideoMethod · 0.92

Calls 2

GetSha1StatusFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected