package zbytes import ( "bytes" "sync" ) type ZBuffer struct { Buff *bytes.Buffer Mu *sync.Mutex } func NewBuffer() *ZBuffer { return &ZBuffer{ Buff: bytes.NewBuffer(nil), Mu: new(sync.Mutex), } } func (z *ZBuffer) Write(p []byte) (n int, err error) { z.Mu.Lock() defer z.Mu.Unlock() return z.Buff.Write(p) } func (z *ZBuffer) WriteRune(r rune) (n int, err error) { z.Mu.Lock() defer z.Mu.Unlock() return z.Buff.WriteRune(r) } func (z *ZBuffer) WriteByte(c byte) error { z.Mu.Lock() z.Mu.Unlock() return z.Buff.WriteByte(c) } func (z *ZBuffer) WriteString(s string) (n int, err error) { z.Mu.Lock() defer z.Mu.Unlock() return z.Buff.WriteString(s) } func (z *ZBuffer) Bytes() []byte { z.Mu.Lock() defer z.Mu.Unlock() return z.Buff.Bytes() } func (z *ZBuffer) String() string { z.Mu.Lock() defer z.Mu.Unlock() return z.Buff.String() } func (z *ZBuffer) Reset() { z.Mu.Lock() defer z.Mu.Unlock() z.Buff.Reset() } func (z *ZBuffer) Len() int { z.Mu.Lock() defer z.Mu.Unlock() return z.Buff.Len() }