c4: github.com/Avalanche-io/c4/store Index | Files

package store

import "github.com/Avalanche-io/c4/store"

github.com/Avalanch-io/c4/store - is a package for representing generic c4 storage. A C4 store abstracts away the details of data management allowing c4 data consumers and producers to store and retreave c4 identified data using the c4 id alone.

A c4 store could represent an object storage bucket, a local filesystem, or the agrigation of many c4 stores. A c4 store can also be used to abstract processes like encryption, creating distributed copies, and on the fly validation.

Index

Package Files

doc.go folder.go logger.go ram.go store.go validating.go

Variables

var ErrInvalidID = fmt.Errorf("c4 id does not match data")
var ErrNotImplemented = fmt.Errorf("not implemented")

ErrNotImplemented is the error to return for unimplemented interface mathods.

type Folder Uses

type Folder string

Folder is an implementation of the Store interface that uses c4 id nameed files in a filsystem folder.

func (Folder) Create Uses

func (f Folder) Create(id c4.ID) (io.WriteCloser, error)

Create creates and opens for writting a file with the given c4 id as it's name if the file does not already exist. If it cannot open the file or the file already exists it returns an error.

func (Folder) Open Uses

func (f Folder) Open(id c4.ID) (io.ReadCloser, error)

Open opens a file named the given c4.ID in read-only mode from the folder. If the file does not exist an error is returned.

func (Folder) Remove Uses

func (f Folder) Remove(id c4.ID) error

type Logger Uses

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

A Logger store wraps a c4 Store and logs a cusomizable set of Store function.

func NewLogger Uses

func NewLogger(s Store, log io.Writer, flags LoggerFlags) *Logger

NewLogger creates a new Logger Store that wrapps a Store and logs function calls and errors to the Store and the io.ReadCloser and io.WriteCloser the Logger Store produces. Which function calls and errors are logged is controlled by setting the appropreate flags. If flags is set to 0 then all flags are enabled so all functions and errors are logged.

func (*Logger) Create Uses

func (l *Logger) Create(id c4.ID) (io.WriteCloser, error)

Create logs and calls the Create method of the contained Store.

func (*Logger) Open Uses

func (l *Logger) Open(id c4.ID) (io.ReadCloser, error)

Open logs and calls the Open method of the contained Store.

func (*Logger) Remove Uses

func (l *Logger) Remove(id c4.ID) error

Remove logs and calls the Remove method of the contained Store.

type LoggerFlags Uses

type LoggerFlags uint32
const (
    LogOpen LoggerFlags = 1 << iota
    LogCreate
    LogRemove
    LogRead
    LogWrite
    LogClose
    LogError
    LogInvalidID
    LogEof
)

type RAM Uses

type RAM map[c4.ID][]byte

A RAM store is an implementation of the Store interface that stores all data in ram.

func NewRAM Uses

func NewRAM() *RAM

func (*RAM) Create Uses

func (s *RAM) Create(id c4.ID) (io.WriteCloser, error)

Create creates an io.WriteCloser interface to a ram buffer, if the data for `id` already exists in the RAM store then an error of type `*os.PathError` is returned.

func (*RAM) Open Uses

func (s *RAM) Open(id c4.ID) (io.ReadCloser, error)

Open opens a file named the given c4.ID in read-only mode from ram. If the file does not exist an error of type `*os.PathError` is returned.

func (*RAM) Remove Uses

func (s *RAM) Remove(id c4.ID) error

Remove removes the c4 id and it's assoceated data from memory, an error is returned if the id does not exist.

type Sink Uses

type Sink interface {
    Create(id c4.ID) (io.WriteCloser, error)
}

Sink - is an interface that defines a destination for data identified by c4 id.

type Source Uses

type Source interface {
    Open(id c4.ID) (io.ReadCloser, error)
}

Source - is an interface that defines a source for data identified by c4 id.

type Store Uses

type Store interface {
    Source
    Sink

    Remove(id c4.ID) error
}

Store - Defines an interface to a data sources that can Open readonly or Create write only data accessed via c4 id. The interface includes a Remove fucntion, but implementation is optional. Implementations should return an appropreate error if Remove is diregarded, such as ErrNotImplemented, os.ErrPermission, etc.

type Validating Uses

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

The Validating store wrapps another c4 store and validates all c4 ids with the data that is read or written. If the data does not match the id, then ErrInvalidC4ID will be returned. C4 id validity is checked when `Close()` is called on the reader, or writter, or when an io.EOF is encountered while reading or writting.

func NewValidating Uses

func NewValidating(s Store) *Validating

func (*Validating) Create Uses

func (v *Validating) Create(id c4.ID) (io.WriteCloser, error)

Create creates and opens for writting a file with the given c4 id as it's name if the file does not already exist. If it cannot open the file or the file already exists is returns an error.

func (*Validating) Open Uses

func (v *Validating) Open(id c4.ID) (io.ReadCloser, error)

Open opens a file named the given c4.ID in read-only mode from the folder. If the file does not exist an error is returned.

func (*Validating) Remove Uses

func (v *Validating) Remove(id c4.ID) error

Package store imports 8 packages (graph). Updated 2019-11-13. Refresh now. Tools for package owners.