io

package
v0.0.0-...-932458b Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockFile

type BlockFile interface {
	io.Closer

	// Alloc should allocate 'n' new sequential blocks and return the id of the
	// first block and slice pointer to the first block.
	Alloc(n int) (id int, slice []byte, err error)

	// Slice returns a slice of the memory mapped region starting at the block
	// with the given id. Alloc() calls may invalidate the returned slice. It
	// is caller's responsibility to co-ordinate Alloc() and Slice() calls.
	Slice(id int) ([]byte, error)

	// Info returns information about the block file state/configuration.
	Info() (name string, count, blockSz int, readOnly bool)
}

BlockFile provides facilities for low-level paged I/O on memory mapped, random access files. BlockFile is NOT safe for concurrent use. BlockFile gives direct access to memory mapped region and incorrect usage can cause segfaults or unexpected behaviors.

func Open

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

Open opens the named file and returns a BlockFile instance for it. If the file doesn't exist, it will be created. If the fileName is ':memory:', an in-memory block-file will be returned.

type InMem

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

InMem implements an ephemeral BlockFile using in-memory byte slice. This implementation of BlockFile is meant for testing only.

func (*InMem) Alloc

func (mem *InMem) Alloc(n int) (int, []byte, error)

Alloc allocates n new sequential blocks and returns the id of the first.

func (*InMem) Close

func (mem *InMem) Close() error

Close flushes any pending writes and closes the file.

func (*InMem) Info

func (mem *InMem) Info() (name string, count, blockSz int, readOnly bool)

Info returns information about the block file state/configuration.

func (*InMem) Slice

func (mem *InMem) Slice(id int) ([]byte, error)

Slice returns a slice of the memory mapped region starting at the block with the given id. Incorrect handling of the returned slice can cause segfaults or unexpected behavior. Any Alloc() calls will invalidate the returned slice.

type OnDisk

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

OnDisk implements a memory mapped BlockFile using an on-disk file.

func (*OnDisk) Alloc

func (bf *OnDisk) Alloc(n int) (int, []byte, error)

Alloc will allocate 'n' sequential blocks and return the first id and slice to the first block.

func (*OnDisk) Close

func (bf *OnDisk) Close() error

Close flushes any pending writes and closes the underlying file.

func (*OnDisk) Info

func (bf *OnDisk) Info() (name string, count, blockSz int, readOnly bool)

Info returns information about the block file state/configuration.

func (*OnDisk) Slice

func (bf *OnDisk) Slice(id int) ([]byte, error)

Slice returns a slice of the memory mapped region starting at the block with the given id. Incorrect handling of the returned slice can cause segfaults or unexpected behavior. Any Alloc() calls may invalidate the returned slice.

Jump to

Keyboard shortcuts

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