mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-06 19:32:49 +08:00
30 lines
493 B
Go
30 lines
493 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"unsafe"
|
|
)
|
|
|
|
func StringToBytes(s string) []byte {
|
|
return *(*[]byte)(unsafe.Pointer(
|
|
&struct {
|
|
string
|
|
Cap int
|
|
}{s, len(s)},
|
|
))
|
|
}
|
|
|
|
func BytesToString(b []byte) string {
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
}
|
|
|
|
func B64Decode(s string) ([]byte, error) {
|
|
dst := make([]byte, base64.StdEncoding.DecodedLen(len(s)))
|
|
n, err := base64.StdEncoding.Decode(dst, []byte(s))
|
|
if err != nil {
|
|
return dst, err
|
|
}
|
|
dst = dst[:n]
|
|
return dst, nil
|
|
}
|