pager

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2024 License: Apache-2.0 Imports: 7 Imported by: 4

README

pager

abstraction for read/write from files by fixed size page. Code was copied and modified from this repository

Documentation

Index

Constants

View Source
const InMemoryFileName = ":memory:"

InMemoryFileName can be passed to Open() to create a pager for an ephemeral in-memory file.

Variables

View Source
var ErrReadOnly = errors.New("read-only")

ErrReadOnly is returned when a write operation is attempted on a read-only pager instance.

Functions

This section is empty.

Types

type Pager

type Pager struct {
	// contains filtered or unexported fields
}

Pager provides facilities for paged I/O on file-like objects with random access. If the underlying file is os.File type, memory mapping will be enabled when file size is non-zero.

func Open

func Open(fileName string, blockSz int, readOnly bool, mode os.FileMode) (*Pager, error)

Open opens the named file and returns a pager instance for it. If the file doesn't exist, it will be created if not in read-only mode.

func (*Pager) Alloc

func (p *Pager) Alloc(n int) (uint64, error)

Alloc allocates 'n' new sequential pages and returns the id of the first page in sequence.

func (*Pager) Close

func (p *Pager) Close() error

Close closes the underlying file and marks the pager as closed for use.

func (*Pager) Count

func (p *Pager) Count() uint64

Count returns the number of pages in the underlying file. Returns error if the file is closed.

func (*Pager) Free

func (p *Pager) Free(n int) error

Free deallocates 'n' sequential pages from end of file

func (*Pager) Marshal

func (p *Pager) Marshal(id uint64, v encoding.BinaryMarshaler) error

Marshal writes the marshaled value of 'v' into page with given id.

func (*Pager) PageSize

func (p *Pager) PageSize() int

PageSize returns the size of one page used by pager.

func (*Pager) Read

func (p *Pager) Read(id uint64) ([]byte, error)

Read reads one page of data from the underlying file or mmapped region if enabled.

func (*Pager) ReadAt

func (p *Pager) ReadAt(dst []byte, offset uint64) error

ReadAt reads length count of bytes starting from offset

func (*Pager) ReadOnly

func (p *Pager) ReadOnly() bool

ReadOnly returns true if the pager instance is in read-only mode.

func (*Pager) Remove

func (p *Pager) Remove()

func (*Pager) Stats

func (p *Pager) Stats() Stats

Stats returns i/o stats collected by this pager.

func (*Pager) String

func (p *Pager) String() string

func (*Pager) Unmarshal

func (p *Pager) Unmarshal(id uint64, into encoding.BinaryUnmarshaler) error

Unmarshal reads the page with given id and unmarshals the page data using 'into' and 'slot'.

func (*Pager) Write

func (p *Pager) Write(id uint64, d []byte) error

Write writes one page of data to the page with given id. Returns error if the data is larger than a page.

func (*Pager) WriteAt

func (p *Pager) WriteAt(src []byte, offset uint64) error

WriteAt writes length count of bytes starting from offset

type RandomAccessFile

type RandomAccessFile interface {
	io.ReaderAt
	io.WriterAt
	io.Closer

	Truncate(size int64) error
	Name() string
}

RandomAccessFile represents a file-like object that can be read from and written to at any offset.

type Stats

type Stats struct {
	Writes int
	Reads  int
	Allocs int
}

Stats represents I/O statistics collected by the pager.

func (Stats) String

func (s Stats) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL