Ai
1 Star 0 Fork 0

长阳/go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bytes.go 914 Bytes
一键复制 编辑 原始数据 按行查看 历史
package s
import (
"encoding/hex"
"os"
)
type Bytes []byte
var (
M_NEW = 1
M_APPEND = 0
)
func (b Bytes) ToFile(fname Str, mode ...int) error {
m := M_APPEND
if mode != nil {
m = mode[0]
}
var f *os.File
var err error
if m == M_APPEND {
f, err = os.OpenFile(fname.String(), os.O_APPEND|os.O_CREATE|os.O_WRONLY, os.ModePerm)
} else {
f, err = os.OpenFile(fname.String(), os.O_TRUNC|os.O_CREATE|os.O_WRONLY, os.ModePerm)
}
if err != nil {
return err
}
_, err = f.Write(b)
if err != nil {
return err
}
return nil
}
func (b Bytes) Len() int {
return len(b)
}
func (b Bytes) Decode() Str {
S, err := AutoDecode(b)
if err != nil {
SafePushErr(err)
return Str("")
}
return S
}
func (b Bytes) Bytes() []byte {
return b
}
func (b Bytes) DecodeHex() Str {
return Str(hex.EncodeToString(b))
}
func MakeBytes(len int) Bytes {
b := make([]byte, len)
return Bytes(b)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dark.H/go-utils.git
git@gitee.com:dark.H/go-utils.git
dark.H
go-utils
go-utils
v1.3.4

搜索帮助