package bytebufferpool

import 

// ByteBuffer provides byte buffer, which can be used for minimizing
// memory allocations.
//
// ByteBuffer may be used with functions appending data to the given []byte
// slice. See example code for details.
//
// Use Get for obtaining an empty byte buffer.
type ByteBuffer struct {

	// B is a byte buffer to use in append-like workloads.
	// See example code for details.
	B []byte
}

// Len returns the size of the byte buffer.
func ( *ByteBuffer) () int {
	return len(.B)
}

// ReadFrom implements io.ReaderFrom.
//
// The function appends all the data read from r to b.
func ( *ByteBuffer) ( io.Reader) (int64, error) {
	 := .B
	 := int64(len())
	 := int64(cap())
	 := 
	if  == 0 {
		 = 64
		 = make([]byte, )
	} else {
		 = [:]
	}
	for {
		if  ==  {
			 *= 2
			 := make([]byte, )
			copy(, )
			 = 
		}
		,  := .Read([:])
		 += int64()
		if  != nil {
			.B = [:]
			 -= 
			if  == io.EOF {
				return , nil
			}
			return , 
		}
	}
}

// WriteTo implements io.WriterTo.
func ( *ByteBuffer) ( io.Writer) (int64, error) {
	,  := .Write(.B)
	return int64(), 
}

// Bytes returns b.B, i.e. all the bytes accumulated in the buffer.
//
// The purpose of this function is bytes.Buffer compatibility.
func ( *ByteBuffer) () []byte {
	return .B
}

// Write implements io.Writer - it appends p to ByteBuffer.B
func ( *ByteBuffer) ( []byte) (int, error) {
	.B = append(.B, ...)
	return len(), nil
}

// WriteByte appends the byte c to the buffer.
//
// The purpose of this function is bytes.Buffer compatibility.
//
// The function always returns nil.
func ( *ByteBuffer) ( byte) error {
	.B = append(.B, )
	return nil
}

// WriteString appends s to ByteBuffer.B.
func ( *ByteBuffer) ( string) (int, error) {
	.B = append(.B, ...)
	return len(), nil
}

// Set sets ByteBuffer.B to p.
func ( *ByteBuffer) ( []byte) {
	.B = append(.B[:0], ...)
}

// SetString sets ByteBuffer.B to s.
func ( *ByteBuffer) ( string) {
	.B = append(.B[:0], ...)
}

// String returns string representation of ByteBuffer.B.
func ( *ByteBuffer) () string {
	return string(.B)
}

// Reset makes ByteBuffer.B empty.
func ( *ByteBuffer) () {
	.B = .B[:0]
}