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.
79 lines
1.6 KiB
79 lines
1.6 KiB
package operaSystem
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func (fl *OperaSystem) ByteToBase64(b []byte) string {
|
|
return base64.StdEncoding.EncodeToString(b)
|
|
}
|
|
|
|
// Base64ToByte base64 string to byte
|
|
// baseStr parameter is base64 string
|
|
func (fl *OperaSystem) 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 *OperaSystem) 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
|
|
}
|
|
|
|
func (fl *OperaSystem) FileName(filePath string) string {
|
|
fileInfo, err := os.Stat(filePath)
|
|
if err == nil {
|
|
return fileInfo.Name()
|
|
}
|
|
return ""
|
|
} // FileName
|
|
|
|
func (fl *OperaSystem) FileSize(filePath string) int64 {
|
|
fileInfo, err := os.Stat(filePath)
|
|
if err == nil {
|
|
return fileInfo.Size()
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (fl *OperaSystem) FileModTime(filePath string) time.Time {
|
|
fileInfo, err := os.Stat(filePath)
|
|
if err == nil {
|
|
return fileInfo.ModTime()
|
|
}
|
|
return time.Time{}
|
|
}
|
|
|
|
func (fl *OperaSystem) FileMode(filePath string) os.FileMode {
|
|
fileInfo, err := os.Stat(filePath)
|
|
if err == nil {
|
|
return fileInfo.Mode()
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (fl *OperaSystem) IsDir(filePath string) bool {
|
|
fileInfo, err := os.Stat(filePath)
|
|
if err == nil {
|
|
return fileInfo.IsDir()
|
|
}
|
|
return false
|
|
}
|