Documentation ¶
Overview ¶
Package byteutil Provide some bytes utils functions or structs
Index ¶
- Variables
- func FirstLine(bs []byte) []byte
- func Md5(src any) []byte
- func SafeString(bs []byte, err error) string
- func StrOrErr(bs []byte, err error) (string, error)
- type Buffer
- func (b *Buffer) MustWriteString(ss ...string)
- func (b *Buffer) QuietWriteByte(c byte)
- func (b *Buffer) QuietWriteString(ss ...string)
- func (b *Buffer) QuietWritef(tpl string, vs ...any)
- func (b *Buffer) QuietWriteln(ss ...string)
- func (b *Buffer) ResetAndGet() string
- func (b *Buffer) WriteAny(vs ...any)
- func (b *Buffer) Writeln(ss ...string)
- type BytesEncoder
- type ChanPool
- type StdEncoder
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // HexEncoder instance HexEncoder = NewStdEncoder(func(src []byte) []byte { dst := make([]byte, hex.EncodedLen(len(src))) hex.Encode(dst, src) return dst }, func(src []byte) ([]byte, error) { n, err := hex.Decode(src, src) return src[:n], err }) // B64Encoder instance B64Encoder = NewStdEncoder(func(src []byte) []byte { b64Dst := make([]byte, base64.StdEncoding.EncodedLen(len(src))) base64.StdEncoding.Encode(b64Dst, src) return b64Dst }, func(src []byte) ([]byte, error) { dBuf := make([]byte, base64.StdEncoding.DecodedLen(len(src))) n, err := base64.StdEncoding.Decode(dBuf, src) if err != nil { return nil, err } return dBuf[:n], err }) )
Functions ¶
func SafeString ¶
SafeString convert to string, return empty string on error.
Types ¶
type Buffer ¶
Buffer wrap and extends the bytes.Buffer
func (*Buffer) MustWriteString ¶
MustWriteString to buffer
func (*Buffer) QuietWriteString ¶
QuietWriteString to buffer
func (*Buffer) QuietWritef ¶
QuietWritef write message to buffer
func (*Buffer) QuietWriteln ¶
QuietWriteln write message to buffer with newline
type BytesEncoder ¶
BytesEncoder interface
type ChanPool ¶
type ChanPool struct {
// contains filtered or unexported fields
}
ChanPool struct
Usage:
bp := strutil.NewByteChanPool(500, 1024, 1024) buf:=bp.Get() defer bp.Put(buf) // use buf do something ...
refer https://www.flysnow.org/2020/08/21/golang-chan-byte-pool.html from https://github.com/minio/minio/blob/master/internal/bpool/bpool.go
func NewChanPool ¶
NewChanPool instance
func (*ChanPool) Get ¶
Get gets a []byte from the BytePool, or creates a new one if none are available in the pool.
type StdEncoder ¶
type StdEncoder struct {
// contains filtered or unexported fields
}
StdEncoder implement the BytesEncoder
func NewStdEncoder ¶
func NewStdEncoder(encFn func(src []byte) []byte, decFn func(src []byte) ([]byte, error)) *StdEncoder
NewStdEncoder instance
Click to show internal directories.
Click to hide internal directories.