no longer use unsafe package for string/bytes conversion

This commit is contained in:
daguang
2022-04-19 17:06:27 +08:00
parent fd92fd2409
commit 308fdccf65
32 changed files with 103 additions and 96 deletions

View File

@ -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.