import "github.com/byte-mug/golibs/flatfile"
const ( MaxRawSize = (1 << 24) // 16 MiB MaxRecordSize = MaxRawSize - 4 // 16 MiB - 4 Byte )
-
var EBadRecord = errors.New("Bad Record")
-
var ERecordTooLong = errors.New("Record Too Long")
-
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 struct { // contains filtered or unexported fields }
-
func (f *FlatFileIterator) Init(src io.ReaderAt)
-
func (f *FlatFileIterator) Next() (recordID int, recordOffset int64, recordLength int, ioError error)
-
type FlatFileReader struct { // contains filtered or unexported fields }
-
func (r *FlatFileReader) FillCache(count int)
-
func (r *FlatFileReader) Init(src io.ReaderAt)
-
func (r *FlatFileReader) InitEx(src io.ReaderAt, maxCache int)
-
func (r *FlatFileReader) ReadEntry(recordID int) (*[]byte, []byte, error)
-
func (r *FlatFileReader) ReadPosition(recordID int) (recordOffset int64, recordLength int, ioError error)
-
type FlatFileWriter struct { // contains filtered or unexported fields }
-
func (w *FlatFileWriter) Append(buf []byte) (recordID int, err error)
-
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 (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 (w *FlatFileWriter) InitNew(dest io.WriterAt)
Initializes the FFWriter, assuming, that dest is empty.
func (w *FlatFileWriter) ShouldHaveLength() int64
-
type PositionCache struct { // contains filtered or unexported fields }
-
func (p *PositionCache) Append(id int, off int64)
-
func (p *PositionCache) Init(max int)
-
func (p *PositionCache) Last() (int, int64, bool)
-
func (p *PositionCache) Search(id int) (int, int64)
-
type ReaderWriter interface { io.ReaderAt io.WriterAt }
-
import "encoding/binary"
import "errors"
import "fmt"
import "github.com/byte-mug/golibs/buffer"
import "io"
import "sort"
import "sync"