You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
848 B

package file
import (
"encoding/base64"
"os"
)
func (fl *File) ByteToBase64(b []byte) string {
return base64.StdEncoding.EncodeToString(b)
}
// Base64ToByte base64 string to byte
// baseStr parameter is base64 string
func (fl *File) Base64ToByte(baseStr string) ([]byte, error) {
return base64.StdEncoding.DecodeString(string(baseStr))
}
// ByteToFile The byte array is converted into a file and landed
// The parameter b is the bate array filePath file path
func (fl *File) ByteToFile(b []byte, filePath string) error {
//Open file Create a file if there is no file
file, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, os.ModePerm)
if err != nil {
return err
}
_, err = file.Write(b)
if err != nil {
return err
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
panic(err)
}
}(file)
return nil
}