/
hash_from.go
74 lines (56 loc) · 1.26 KB
/
hash_from.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
package hash
import (
"io"
"bytes"
)
// 字节
func (this Hash) FromBytes(data []byte) Hash {
this.data = data
return this
}
// 字节
func FromBytes(data []byte) Hash {
return defaultHash.FromBytes(data)
}
// 字符
func (this Hash) FromString(data string) Hash {
this.data = []byte(data)
return this
}
// 字符
func FromString(data string) Hash {
return defaultHash.FromString(data)
}
// FromBase64String
func (this Hash) FromBase64String(data string) Hash {
this.data, this.Error = this.Base64Decode(data)
return this
}
// FromBase64String
func FromBase64String(data string) Hash {
return defaultHash.FromBase64String(data)
}
// FromHexString
func (this Hash) FromHexString(data string) Hash {
this.data, this.Error = this.HexDecode(data)
return this
}
// FromHexString
func FromHexString(data string) Hash {
return defaultHash.FromHexString(data)
}
// FromReader
func (this Hash) FromReader(reader io.Reader) Hash {
buf := bytes.NewBuffer(nil)
// 保存
if _, err := io.Copy(buf, reader); err != nil {
this.Error = err
return this
}
this.data = buf.Bytes()
return this
}
// FromReader
func FromReader(reader io.Reader) Hash {
return defaultHash.FromReader(reader)
}