func NewBufferPersistent(path string, capacity int) (*Buffer, error) {
	file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		return nil, err
	}
	buffer, err := newBufferFile(file, capacity)
	if err != nil {
		return nil, err
	}
	buffer.persistent = true
	return buffer, nil
}
It is the caller's responsibility to set offset after this, because Buffer
doesn't remember what it was.
package z
import (
	"encoding/binary"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
	"sync/atomic"
	"github.com/golang/glog"
	"github.com/pkg/errors"
)
const (
	defaultCapacity = 64
	defaultTag      = "buffer"
)
type Buffer struct {
	padding       uint64      
	offset        uint64      
	buf           []byte      
	bufType       BufferType  
	curSz         int         
	maxSz         int         
	mmapFile      *MmapFile   
	autoMmapAfter int         
	autoMmapDir   string      
	persistent    bool        
	tag           string      
}
func NewBuffer(capacity int, tag string) *Buffer {
	if capacity < defaultCapacity {
		capacity = defaultCapacity
	}
	if tag == "" {
		tag = defaultTag
	}
	return &Buffer{
		buf:     Calloc(capacity, tag),
		bufType: UseCalloc,
		curSz:   capacity,
		offset:  8,
		padding: 8,
		tag:     tag,
	}
}