func (b *KeyBuffer) SuffixForRead(n int) []byte {
	start := keyPrefixSize + b.keyLen
	if len(b.buf) < start+n {
		b.buf = append(b.buf[:start], make([]byte, n)...)  
	}
	return b.buf[start : start+n]
}
Return a slice of size n suitable for using with an io.Reader
The read bytes will overwrite the first n bytes of suffix (if they exist)
package main
import (
	"bytes"
	"encoding/binary"
)
const keyPrefixSize = 5
type KeyBuffer struct {
	buf        []byte
	keyLen     int
	reverseKey bool
}
func NewKeyBuffer(t byte, key []byte, extra int) *KeyBuffer {
	k := &KeyBuffer{make([]byte, keyPrefixSize, keyPrefixSize+len(key)+extra), len(key), false}
	k.buf[0] = t
	k.SetKey(key)
	return k
}
func NewKeyBufferWithSuffix(t byte, key []byte, suffix []byte) *KeyBuffer {
	k := &KeyBuffer{make([]byte, keyPrefixSize, keyPrefixSize+len(key)+len(suffix)), len(key), false}
	k.buf[0] = t
	k.SetKey(key)
	k.SetSuffix(suffix)
	return k
}
func (b *KeyBuffer) SetKey(key []byte) {
	if len(key) == 0 {
		return
	}
	b.keyLen = len(key)
	binary.BigEndian.PutUint32(b.buf[1:], uint32(len(key)))
	b.buf = append(b.buf[:keyPrefixSize], key...)
}
func (b *KeyBuffer) SetSuffix(s []byte) {
	b.buf = append(b.buf[:keyPrefixSize+b.keyLen], s...)
}