func (b *buffer) addIndex(i int, n int) int {
	i += n - len(b.data)
	if i < 0 {
		i += len(b.data)
	}
	return i
}
addIndex adds a non-negative integer to the index i and returns the
resulting index. The function takes care of wrapping the index as
well as potential overflow situations.
package lzma
import (
	"errors"
)
type buffer struct {
	data  []byte
	front int
	rear  int
}
func newBuffer(size int) *buffer {
	return &buffer{data: make([]byte, size+1)}
}
func (b *buffer) Cap() int {
	return len(b.data) - 1
}
func (b *buffer) Reset() {
	b.front = 0
	b.rear = 0
}
func (b *buffer) Buffered() int {
	delta := b.front - b.rear
	if delta < 0 {
		delta += len(b.data)
	}
	return delta
}
func (b *buffer) Available() int {
	delta := b.rear - 1 - b.front
	if delta < 0 {
		delta += len(b.data)
	}
	return delta
}