Documentation
¶
Overview ¶
Package filebuffer provides a file buffer implementation for random access of fixed size files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileBuffer ¶
type FileBuffer struct {
// contains filtered or unexported fields
}
FileBuffer is a file buffer which can read the file partialy in page size units.
FileBuffer assumes the file size never changes.
FileBuffer uses vector I/O (preadv and pwritev) on Linux for reading and writing successive pages in the file.
FileBuffer implements ReadWriterAt interface.
func New ¶
func New(file *os.File, fileSize, pageSize int64) *FileBuffer
New creates a new whole file buffer.
func (*FileBuffer) Preread ¶
func (b *FileBuffer) Preread(off, length int64) error
Preread reads a bytes of the specified length starting at offset off data from the underlying file.
It reads the file in page size units and skips pages which were already read and kept in the buffer.
func (*FileBuffer) ReadAt ¶
func (b *FileBuffer) ReadAt(p []byte, off int64) (n int, err error)
ReadAt reads len(p) bytes into p starting at offset off in the buffer. It returns the number of bytes read (n == len(p)) and any error encountered.
ReadAt reads necessary pages using Preread method which are not already read.
If you are going to call ReadAt multiple times to get data spanning to multiple pages, you may want to call Preread for the total range beforehand to reduce file I/O system calls.
ReadAt implements io.ReaderAt interface.
func (*FileBuffer) WriteAt ¶
func (b *FileBuffer) WriteAt(p []byte, off int64) (n int, err error)
WriteAt writes len(p) bytes from p to the buffer at offset off. It returns the number of bytes written from p (n == len(p)) and any error encountered that caused the write to stop early.
Pages for the corresponding range will be read first if not already read.
The caller must call Flush later to write dirty pages to the file.
WriteAt implements io.WriterAt interface.