func (b *Batch) EnsureNewline() {
	n := len(b.buf)
	if n > 0 && b.buf[n-1] != '\n' {
		b.appendImpl([]byte{'\n'})
	}
}
EnsureNewline adds a newline to the end of the batch if there
isn't one already present.
package batch
import (
	"io"
	"time"
)
const maxReadSize = 65536
func New(capacity int) *Batch {
	return &Batch{
		buf:     make([]byte, 0, capacity),
		created: clock.Now(),
	}
}
type Batch struct {
	buf     []byte
	writes  int
	created time.Time
}
func (b *Batch) Size() int {
	return len(b.buf)
}
func (b *Batch) Remaining() int {
	return cap(b.buf) - len(b.buf)
}
func (b *Batch) Bytes() []byte {
	return b.buf
}
func (b *Batch) CopyBytes() []byte {
	out := make([]byte, len(b.buf))
	copy(out, b.buf)
	return out
}
func (b *Batch) Writes() int {
	return b.writes
}
func (b *Batch) Age() time.Duration {
	if b.writes <= 0 {
		return time.Duration(0)
	}
	return clock.Since(b.created)
}
func (b *Batch) Reset() {
	b.buf = b.buf[:0]
	b.writes = 0
	b.created = clock.Now()
}
func (b *Batch) Append(more []byte) {
	b.countWrite()
	b.appendImpl(more)
}
func (b *Batch) ReadFrom(r io.Reader) (int64, error) {
	var total int64
	for {
		b.growIfLow()
		n, err := r.Read(b.buf[len(b.buf):cap(b.buf)])
		if n > 0 {
			b.buf = b.buf[:len(b.buf)+n]
			total += int64(n)
		}
		if err != nil {
			if total > 0 {
				b.countWrite()
			}
			if err == io.EOF {
				err = nil
			}
			return total, err
		}
	}
}
func (b *Batch) ReadOnceFrom(r io.Reader) (int, error) {
	b.growIfLow()
        n, err := r.Read(b.buf[len(b.buf):cap(b.buf)])
	if n > 0 {
		b.buf = b.buf[:len(b.buf)+n]
		b.countWrite()
	}
	if err == io.EOF {
		err = nil
	}
	return n, err
}
func (b *Batch) growIfLow() {
	if b.Remaining() < maxReadSize {
		b.grow()
	}
}
func (b *Batch) grow() {
	newSize := cap(b.buf) * 2
	if newSize < maxReadSize {
		newSize = cap(b.buf) + maxReadSize
	}
	newBuf := make([]byte, int(newSize))
	copy(newBuf, b.buf)
	newBuf = newBuf[:len(b.buf)]
	b.buf = newBuf
}