func (b *Buffer) Close() error {
	b.lock.Lock()
	defer b.lock.Unlock()
	b.data = nil
	b.reader = nil
	if b.mode == FileMode {
		name := b.f.Name()
		b.f.Close()
		b.f = nil
		os.Remove(name)
	}
	return nil
}
Close and release
package seekbuf
import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"os"
	"sync"
)
type Buffer struct {
	reader io.Reader
	data   []byte
	len    int64
	pos    int64
	mode   Mode
	f      *os.File
	lock   sync.Mutex
}
var _ io.ReaderAt = (*Buffer)(nil)
var _ io.ReadSeeker = (*Buffer)(nil)
var _ io.Closer = (*Buffer)(nil)
type Mode int
const (
	FileMode = Mode(0)
	MemoryMode = Mode(1)
)
var (
	ErrModeNotFound = errors.New("mode not found")
)
func Open(r io.Reader, m Mode) (*Buffer, error) {
	switch m {
	case FileMode:
		f, err := os.CreateTemp("", "seekbuf-")
		if err != nil {
			return nil, err
		}
		return &Buffer{reader: r, mode: m, f: f}, nil
	case MemoryMode:
		return &Buffer{reader: r, mode: m}, nil
	}
	return nil, ErrModeNotFound
}