binary

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileClosed    = errors.New("binary: file closed")
	ErrBadEntry      = errors.New("binary: bad entry")
	ErrEntryNotFound = errors.New("binary: entry not found")
	ErrKeyTooLarge   = errors.New("binary: key too large")
	ErrValueTooLarge = errors.New("binary: value too large")
)

Functions

func EncodeEntry

func EncodeEntry(w io.WriteSeeker, e *Entry) (int64, error)

EncodeEntry writes the provided entry to the writer provided

func EncodeIndex

func EncodeIndex(w io.WriteSeeker, e *Index) (int64, error)

EncodeIndex encodes and writes the provided entry index to w

func Offset

func Offset(rw io.ReadWriteSeeker) (int64, error)

Offset returns the *ReadWriteSeeker's current file pointer offset

Types

type Batch added in v1.3.1

type Batch struct {
	Entries []*Entry
}

func NewBatch added in v1.3.1

func NewBatch() *Batch

func (*Batch) Len added in v1.3.1

func (b *Batch) Len() int

Len [implementing sort interface]

func (*Batch) Less added in v1.3.1

func (b *Batch) Less(i, j int) bool

Less [implementing sort interface]

func (*Batch) String added in v1.3.1

func (b *Batch) String() string

func (*Batch) Swap added in v1.3.1

func (b *Batch) Swap(i, j int)

Swap [implementing sort interface]

func (*Batch) Write added in v1.3.1

func (b *Batch) Write(key string, value []byte)

func (*Batch) WriteEntry added in v1.3.1

func (b *Batch) WriteEntry(e *Entry)

type Entry

type Entry struct {
	Key   []byte
	Value []byte
}

Entry is a key-value data entry

func DecodeEntry

func DecodeEntry(r io.Reader) (*Entry, error)

DecodeEntry encodes the next entry from the reader provided

func DecodeEntryAt

func DecodeEntryAt(r io.ReaderAt, offset int64) (*Entry, error)

DecodeEntryAt decodes the entry from the reader provided at the offset provided

func (*Entry) CheckSize added in v1.7.0

func (de *Entry) CheckSize(maxKeySize, maxValueSize uint) error

CheckSize take a maximum key and maximum value size and checks to ensure the entry key and value do not exceed the specified max sizes. It returns a nil error if all is okay, otherwise ErrKeyTooLarge or ErrValueTooLarge

func (*Entry) Size added in v1.6.0

func (de *Entry) Size() int

Size returns the approximate size of the entry in bytes

func (*Entry) String

func (de *Entry) String() string

String is the stringer method for a *Entry

type Index

type Index struct {
	Key    []byte
	Offset int64
}

Index is a binary entry index

func DecodeIndex

func DecodeIndex(r io.Reader) (*Index, error)

DecodeIndex reads and decodes the provided entry index from r

func DecodeIndexAt

func DecodeIndexAt(r io.ReaderAt, offset int64) (*Index, error)

DecodeIndexAt decodes the index at the provided offset using the provided reader

func (*Index) String

func (di *Index) String() string

String is the stringer method for a *Index

type Reader

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

Reader provides a read-only file descriptor

func OpenReader

func OpenReader(path string) (*Reader, error)

OpenReader returns a *reader for the file at the provided path

func (*Reader) Close

func (r *Reader) Close() error

Close simply closes the *Reader

func (*Reader) Offset

func (r *Reader) Offset() (int64, error)

Offset returns the *Reader's current file pointer offset

func (*Reader) ReadEntry

func (r *Reader) ReadEntry() (*Entry, error)

ReadEntry reads the next encoded entry, sequentially

func (*Reader) ReadEntryAt

func (r *Reader) ReadEntryAt(offset int64) (*Entry, error)

ReadEntryAt reads the encoded entry at the offset provided

func (*Reader) ReadFrom

func (r *Reader) ReadFrom(path string) (*Reader, error)

ReadFrom checks the given path and if it matches, simply returns the same reader, but if it is different it opens a new one recycling the same file descriptor. this allows you to read from multiple files fairly quickly and pain free.

func (*Reader) ReadIndex

func (r *Reader) ReadIndex() (*Index, error)

ReadIndex reads the next encoded index, sequentially

func (*Reader) ReadIndexAt

func (r *Reader) ReadIndexAt(offset int64) (*Index, error)

ReadIndexAt reads the encoded entry index at the offset provided

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

Seek exposes io.Seeker

type Writer

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

Writer provides a write-only file descriptor

func OpenWriter

func OpenWriter(path string) (*Writer, error)

OpenWriter returns a *writer for the file at the provided path

func OpenWriterWithSync

func OpenWriterWithSync(path string, doSync bool) (*Writer, error)

func (*Writer) Close

func (w *Writer) Close() error

Close syncs and closes the *writer

func (*Writer) Offset

func (w *Writer) Offset() (int64, error)

Offset returns the *Writer's current file pointer offset

func (*Writer) SetSyncOnWrite

func (w *Writer) SetSyncOnWrite(ok bool)

func (*Writer) Sync

func (w *Writer) Sync() error

Sync syncs

func (*Writer) WriteEntry

func (w *Writer) WriteEntry(e *Entry) (int64, error)

WriteEntry writes the provided entry to disk

func (*Writer) WriteIndex

func (w *Writer) WriteIndex(e *Index) (int64, error)

WriteIndex writes the provided entry index to disk

Jump to

Keyboard shortcuts

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