-
Notifications
You must be signed in to change notification settings - Fork 3
/
encode.go
40 lines (32 loc) · 1000 Bytes
/
encode.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
package base64Kit
import (
"github.com/richelieu-yang/chimera/v3/src/file/fileKit"
)
func Encode(src []byte, options ...Base64Option) []byte {
opts := loadOptions(options...)
return opts.Encode(src)
}
func EncodeToString(src []byte, options ...Base64Option) string {
opts := loadOptions(options...)
return opts.EncodeToString(src)
}
// EncodeStringToString (拓展) string => base64 string
func EncodeStringToString(s string, options ...Base64Option) string {
return EncodeToString([]byte(s), options...)
}
// EncodeFile (拓展)file => []byte
func EncodeFile(path string, options ...Base64Option) ([]byte, error) {
data, err := fileKit.ReadFile(path)
if err != nil {
return nil, err
}
return Encode(data, options...), nil
}
// EncodeFileToString (拓展)file => string
func EncodeFileToString(path string, options ...Base64Option) (string, error) {
data, err := fileKit.ReadFile(path)
if err != nil {
return "", err
}
return EncodeToString(data, options...), nil
}