mirror of
https://gitee.com/johng/gf
synced 2026-07-05 21:32:17 +08:00
no longer use unsafe package for string/bytes conversion
This commit is contained in:
@ -9,7 +9,6 @@ package gbase64
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
@ -27,7 +26,7 @@ func EncodeString(src string) string {
|
||||
|
||||
// EncodeToString encodes bytes to string with BASE64 algorithm.
|
||||
func EncodeToString(src []byte) string {
|
||||
return gconv.UnsafeBytesToStr(Encode(src))
|
||||
return string(Encode(src))
|
||||
}
|
||||
|
||||
// EncryptFile encodes file content of <path> using BASE64 algorithms.
|
||||
@ -55,7 +54,7 @@ func EncodeFileToString(path string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return gconv.UnsafeBytesToStr(content), nil
|
||||
return string(content), nil
|
||||
}
|
||||
|
||||
// MustEncodeFileToString encodes file content of <path> to string using BASE64 algorithms.
|
||||
@ -103,7 +102,7 @@ func MustDecodeString(data string) []byte {
|
||||
// DecodeString decodes string with BASE64 algorithm.
|
||||
func DecodeToString(data string) (string, error) {
|
||||
b, err := DecodeString(data)
|
||||
return gconv.UnsafeBytesToStr(b), err
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// MustDecodeToString decodes string with BASE64 algorithm.
|
||||
|
||||
Reference in New Issue
Block a user