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