Commit 6b3eeb2f authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

zbytes

parent ad3568f1
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()
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment