cirfile

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const CurrentVersion = 1
View Source
const FilePosEmpty = -1 // sentinel, if startpos is set to -1, file is empty
View Source
const FullHeaderFmt = "%-255s\n" // 256 bytes (255 + newline)
View Source
const HeaderFmt1 = "CBUF%02d %19d %19d %19d %19d\n" // 87 bytes

CBUF[version] [maxsize] [fileoffset] [startpos] [endpos]

View Source
const HeaderLen = 256 // set to 256 for future expandability
View Source
const InitialLockDelay = 10 * time.Millisecond
View Source
const InitialLockTries = 5
View Source
const LockDelay = 100 * time.Millisecond

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	OSFile       *os.File
	Version      byte
	MaxSize      int64
	FileOffset   int64
	StartPos     int64
	EndPos       int64
	FileDataSize int64 // size of data (does not include header size)
	FlockStatus  int
}

File objects are *not* multithread safe, operations must be externally synchronized

func CreateCirFile

func CreateCirFile(fileName string, maxSize int64) (*File, error)

if the file already exists, it is an error. there is a race condition if two goroutines try to create the same file between Stat() and Create(), so

they both might get no error, but only one file will be valid.  if this is a concern, this call
should be externally synchronized.

func OpenCirFile

func OpenCirFile(fileName string) (*File, error)

does not read metadata because locking could block/fail. we want to be able to return a valid file struct without blocking.

func (*File) AppendData

func (f *File) AppendData(ctx context.Context, buf []byte) error

func (*File) Close

func (f *File) Close() error

func (*File) GetStartOffsetAndSize

func (f *File) GetStartOffsetAndSize(ctx context.Context) (int64, int64, error)

returns (fileOffset, datasize, error) datasize is the current amount of readable data held in the cirfile

func (*File) ReadAll

func (f *File) ReadAll(ctx context.Context) (int64, []byte, error)

returns (offset, data, err)

func (*File) ReadAtWithMax

func (f *File) ReadAtWithMax(ctx context.Context, offset int64, maxSize int64) (int64, []byte, error)

func (*File) ReadMeta

func (f *File) ReadMeta(ctx context.Context) error

func (*File) ReadNext

func (f *File) ReadNext(ctx context.Context, buf []byte, offset int64) (int64, int, error)

returns (realOffset, numread, error) will only return io.EOF when len(data) == 0, otherwise will just do a short read

func (*File) WriteAt

func (f *File) WriteAt(ctx context.Context, buf []byte, writePos int64) error

does not implement io.WriterAt (needs context)

type Stat

type Stat struct {
	Location   string
	Version    byte
	MaxSize    int64
	FileOffset int64
	DataSize   int64
}

func StatCirFile

func StatCirFile(ctx context.Context, fileName string) (*Stat, error)

Jump to

Keyboard shortcuts

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