-
Notifications
You must be signed in to change notification settings - Fork 3
/
decode.go
49 lines (45 loc) · 1.36 KB
/
decode.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
package base64Kit
func Decode(src []byte, options ...Base64Option) ([]byte, error) {
opts := loadOptions(options...)
return opts.Decode(src)
}
func DecodeString(s string, options ...Base64Option) ([]byte, error) {
opts := loadOptions(options...)
return opts.DecodeString(s)
}
// DecodeStringToString (拓展) base64 string => string
func DecodeStringToString(s string, options ...Base64Option) (string, error) {
data, err := DecodeString(s, options...)
return string(data), err
}
//// Decode []byte => []byte
///*
//参考: gbase64.Decode()
//*/
//func Decode(data []byte, options ...Base64Option) ([]byte, error) {
// opts := loadOptions(options...)
//
// rst := make([]byte, opts.encoding.DecodedLen(len(data)))
// n, err := opts.encoding.Decode(rst, data)
// if err != nil {
// return nil, err
// }
// return rst[:n], nil
//}
//
//// DecodeToString []byte => string
//func DecodeToString(data []byte, options ...Base64Option) (string, error) {
// rst, err := Decode(data, options...)
// return string(rst), err
//}
//
//// DecodeString string => []byte
//func DecodeString(str string, options ...Base64Option) ([]byte, error) {
// return Decode([]byte(str), options...)
//}
//
//// DecodeStringToString string => string
//func DecodeStringToString(str string, options ...Base64Option) (string, error) {
// rst, err := DecodeString(str, options...)
// return string(rst), err
//}