Package flatfile

import "github.com/byte-mug/golibs/flatfile"

Overview

Index

Constants

const (
	MaxRawSize	= (1 << 24)		// 16 MiB
	MaxRecordSize	= MaxRawSize - 4	// 16 MiB - 4 Byte
)

-

Variables

var EBadRecord = errors.New("Bad Record")

-

var ERecordTooLong = errors.New("Record Too Long")

-

func ScanFlatFile

func ScanFlatFile(r io.ReaderAt) (recs int, off int64, err error)

Scans a flat-file until the end, and then it returns its length.

It will always return an error, usually EBadRecord or io.EOF, depending on the consistency of the file. If the file was corrupted, it will read until the last usable record.

type FlatFileIterator

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

-

func (*FlatFileIterator) Init

func (f *FlatFileIterator) Init(src io.ReaderAt)

-

func (*FlatFileIterator) Next

func (f *FlatFileIterator) Next() (recordID int, recordOffset int64, recordLength int, ioError error)

-

type FlatFileReader

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

-

func (*FlatFileReader) FillCache

func (r *FlatFileReader) FillCache(count int)

-

func (*FlatFileReader) Init

func (r *FlatFileReader) Init(src io.ReaderAt)

-

func (*FlatFileReader) InitEx

func (r *FlatFileReader) InitEx(src io.ReaderAt, maxCache int)

-

func (*FlatFileReader) ReadEntry

func (r *FlatFileReader) ReadEntry(recordID int) (*[]byte, []byte, error)

-

func (*FlatFileReader) ReadPosition

func (r *FlatFileReader) ReadPosition(recordID int) (recordOffset int64, recordLength int, ioError error)

-

type FlatFileWriter

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

-

func (*FlatFileWriter) Append

func (w *FlatFileWriter) Append(buf []byte) (recordID int, err error)

-

func (*FlatFileWriter) InitAppend

func (w *FlatFileWriter) InitAppend(dest ReaderWriter) (err error)

Scans a flat-file until the end, and then use its length and record count to initialize the FFWriter.

It will always return an error, usually EBadRecord or io.EOF, depending on the consistency of the file. If the file was corrupted, it will read until the last usable record. After that, it will append new Entries.

func (*FlatFileWriter) InitEx

func (w *FlatFileWriter) InitEx(dest io.WriterAt, recs int, length int64)

Danger-Zone. Use this function, if and only if, you know what you are doing.

This function initializes the FFWriter using a given number of records, and a given length. If the number of recs is incorrect, the returned ids will be wrong. If the length is incorrect, the file will be corrupted.

func (*FlatFileWriter) InitNew

func (w *FlatFileWriter) InitNew(dest io.WriterAt)

Initializes the FFWriter, assuming, that dest is empty.

func (*FlatFileWriter) ShouldHaveLength

func (w *FlatFileWriter) ShouldHaveLength() int64

-

type PositionCache

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

-

func (*PositionCache) Append

func (p *PositionCache) Append(id int, off int64)

-

func (*PositionCache) Init

func (p *PositionCache) Init(max int)

-

func (*PositionCache) Last

func (p *PositionCache) Last() (int, int64, bool)

-

func (*PositionCache) Search

func (p *PositionCache) Search(id int) (int, int64)

-

type ReaderWriter

type ReaderWriter interface {
	io.ReaderAt
	io.WriterAt
}

-

Dependencies