/
hash_sum.go
84 lines (63 loc) · 1.16 KB
/
hash_sum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package hash
import (
"io"
"hash"
)
// Write
func (this Hash) Write(p []byte) Hash {
this.hash.Write(p)
return this
}
// WriteString
func (this Hash) WriteString(s string) Hash {
p := []byte(s)
this.hash.Write(p)
return this
}
// WriteReader
func (this Hash) WriteReader(reader io.Reader) Hash {
h := this.hash
_, err := io.Copy(h, reader)
if err != nil {
this.Error = err
return this
}
this.hash = h
return this
}
// Sum
func (this Hash) Sum(in []byte) Hash {
this.data = this.hash.Sum(in)
return this
}
// Sum32
func (this Hash) Sum32() uint32 {
if hash32, ok := this.hash.(hash.Hash32); ok {
return hash32.Sum32()
}
return 0
}
// Sum64
func (this Hash) Sum64() uint64 {
if hash64, ok := this.hash.(hash.Hash64); ok {
return hash64.Sum64()
}
return 0
}
// Reset
func (this Hash) Reset() Hash {
this.hash.Reset()
return this
}
// Size
func (this Hash) Size() int {
return this.hash.Size()
}
// BlockSize
func (this Hash) BlockSize() int {
return this.hash.BlockSize()
}
// Hash
func (this Hash) Hash() hash.Hash {
return this.hash
}