cadata

package
v0.0.0-...-36bb858 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MPL-2.0 Imports: 13 Imported by: 54

Documentation

Index

Constants

View Source
const (
	IDSize = 32
	// Base64Alphabet is used when encoding IDs as base64 strings.
	// It is a URL and filepath safe encoding, which maintains ordering.
	Base64Alphabet = "-0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "_" + "abcdefghijklmnopqrstuvwxyz"
)
View Source
const DefaultMaxSize = 1 << 20

Variables

View Source
var (
	ErrTooLarge = errors.New("data is too large for store")
	ErrBadData  = errors.New("data does not match ID")
)

Functions

func Check

func Check(hf HashFunc, id ID, data []byte) error

Check ensures that hf(data) == id and returns ErrBadData if it does not.

func Copy

func Copy(ctx context.Context, dst Poster, src Getter, id ID) error

Copy copies the data referenced by id from src to dst.

func CopyAll

func CopyAll(ctx context.Context, dst Poster, src GetLister) error

CopyAll copies all the data from src to dst

func CopyAllBasic

func CopyAllBasic(ctx context.Context, dst Poster, src GetLister) error

func DeleteAll

func DeleteAll(ctx context.Context, s Store) error

DeleteAll deletes all the data in s

func ForEach

func ForEach(ctx context.Context, s Lister, span Span, fn func(ID) error) error

ForEachSpan calls fn with every ID in the range

func GetBytes

func GetBytes(ctx context.Context, s Getter, id ID) ([]byte, error)

func GetF

func GetF(ctx context.Context, s Getter, id ID, fn func([]byte) error) error

func IsNotFound

func IsNotFound(err error) bool

func IsTooLarge

func IsTooLarge(err error) bool

Types

type Adder

type Adder interface {
	// Add adds data to the store by ID.
	// It will return ErrNotFound if the data cannot be added.
	Add(ctx context.Context, id ID) error
}

Adder defines the Add method

type CopyAllFrom

type CopyAllFrom interface {
	CopyAllFrom(ctx context.Context, src Getter) error
}

type Deleter

type Deleter interface {
	// Delete removes the data identified by id from the store
	Delete(ctx context.Context, id ID) error
}

Deleter defines the Delete method

type ErrNotFound

type ErrNotFound = state.ErrNotFound[ID]

type Exister

type Exister interface {
	// Exists returns true, nil if the ID exists, and false, nil if it does not.
	// The boolean should not be interpretted if err != nil
	Exists(ctx context.Context, id ID) (bool, error)
}

Exister defines the Exists method

type GetLister

type GetLister interface {
	Lister
	Getter
}

GetLister combines the Getter and Lister interfaces

type GetPoster

type GetPoster interface {
	Getter
	Poster
}

type Getter

type Getter interface {
	// Get copies data identified by id into buf.
	// If not all the data can be copied, it returns io.ErrShortBuffer
	// Otherwise n will be the number of bytes copied into buf.
	Get(ctx context.Context, id ID, buf []byte) (int, error)
	Hash(x []byte) ID
	MaxSize() int
}

Getter defines the Get method

type HashFunc

type HashFunc = func(data []byte) ID

type ID

type ID [IDSize]byte

ID identifies a particular piece of data

func BeginFromSpan

func BeginFromSpan(x Span) ID

BeginFromSpan returns the ID which begins the span. It will be lteq every other ID in the Span.

func DefaultHash

func DefaultHash(x []byte) ID

func EndFromSpan

func EndFromSpan(x Span) (ID, bool)

EndFromSpan returns the cadata.ID which is greater than ever ID in the span, and true. Or it returns the zero ID and false if no such ID exists.

func IDFromBytes

func IDFromBytes(x []byte) ID

func (ID) Compare

func (a ID) Compare(b ID) int

func (ID) Equals

func (a ID) Equals(b ID) bool

func (ID) IsZero

func (id ID) IsZero() bool

func (ID) MarshalBase64

func (id ID) MarshalBase64() ([]byte, error)

MarshalBase64 encodes ID using Base64Alphabet

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (*ID) Scan

func (id *ID) Scan(x interface{}) error

func (ID) String

func (id ID) String() string

func (ID) Successor

func (id ID) Successor() ID

Successor returns the ID immediately after this ID

func (*ID) UnmarshalBase64

func (id *ID) UnmarshalBase64(data []byte) error

UnmarshalBase64 decodes data into the ID using Base64Alphabet

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

func (ID) Value

func (id ID) Value() (driver.Value, error)

type Lister

type Lister interface {
	// List reads IDs from the store, in asceding order into ids.
	// All the ids will be >= gteq, if it is not nil.
	// All the ids will be < lt if it is not nil.
	List(ctx context.Context, span Span, ids []ID) (int, error)
}

Lister defines the List method

type MemStore

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

func NewMem

func NewMem(hf HashFunc, maxSize int) *MemStore

func (*MemStore) Delete

func (s *MemStore) Delete(ctx context.Context, id ID) error

func (*MemStore) Exists

func (s *MemStore) Exists(ctx context.Context, id ID) (bool, error)

func (*MemStore) Get

func (s *MemStore) Get(ctx context.Context, id ID, buf []byte) (int, error)

func (*MemStore) Hash

func (s *MemStore) Hash(x []byte) ID

func (*MemStore) Len

func (s *MemStore) Len() (count int)

func (*MemStore) List

func (s *MemStore) List(ctx context.Context, span Span, ids []ID) (n int, err error)

func (*MemStore) MaxSize

func (s *MemStore) MaxSize() int

func (*MemStore) Post

func (s *MemStore) Post(ctx context.Context, data []byte) (ID, error)

type PostExister

type PostExister interface {
	Poster
	Exister
}

type Poster

type Poster interface {
	// Post will store data, and return an ID that can be used to retrieve it later
	Post(ctx context.Context, data []byte) (ID, error)
	MaxSize() int
	Hash(x []byte) ID
}

Poster defines the Post method

type Set

type Set interface {
	Adder
	Deleter
	Exister
	Lister
}

type Span

type Span = state.Span[ID]

Span is a Span of ID's

type Store

type Store interface {
	Poster
	Getter
	Deleter
	Lister
	Exister
}

type Void

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

func NewVoid

func NewVoid(hf HashFunc, maxSize int) Void

func (Void) Delete

func (s Void) Delete(ctx context.Context, id ID) error

func (Void) Exists

func (s Void) Exists(ctx context.Context, id ID) (bool, error)

func (Void) Get

func (s Void) Get(ctx context.Context, id ID, buf []byte) (int, error)

func (Void) Hash

func (s Void) Hash(x []byte) ID

func (Void) List

func (s Void) List(ctx context.Context, span Span, ids []ID) (int, error)

func (Void) MaxSize

func (s Void) MaxSize() int

func (Void) Post

func (s Void) Post(ctx context.Context, data []byte) (ID, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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