Documentation
¶
Overview ¶
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 ¶
- Variables
- type Folder
- type Logger
- type LoggerFlags
- type MAP
- func (s MAP) Create(id c4.ID) (io.WriteCloser, error)
- func (m MAP) Delete(id c4.ID)
- func (m MAP) Load(id c4.ID) (path string)
- func (m MAP) LoadOrStore(id c4.ID, path string) (actual string, loaded bool)
- func (s MAP) Open(id c4.ID) (io.ReadCloser, error)
- func (m MAP) Range(f func(id c4.ID, path string) bool)
- func (s MAP) Remove(id c4.ID) error
- type RAM
- type Sink
- type Source
- type Store
- type Validating
Constants ¶
This section is empty.
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.
Functions ¶
This section is empty.
Types ¶
type Folder ¶
type Folder string
Folder is an implementation of the Store interface that uses c4 id nameed files in a filsystem folder.
func (Folder) Create ¶
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.
type Logger ¶
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 ¶
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.
type LoggerFlags ¶
type LoggerFlags uint32
const ( LogOpen LoggerFlags = 1 << iota LogCreate LogRemove LogRead LogWrite LogClose LogError LogInvalidID LogEof )
type MAP ¶
A MAP store is an implementation of the Store interface that stores all data in ram.
func (MAP) Create ¶
Create creates an io.WriteCloser interface to a ram buffer, if the data for `id` already exists in the MAP store then an error of type `*os.PathError` is returned.
func (MAP) LoadOrStore ¶
type RAM ¶
A RAM store is an implementation of the Store interface that stores all data in ram.
func (*RAM) Create ¶
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.
type Sink ¶
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 ¶
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 ¶
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 ¶
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 ¶
func NewValidating(s Store) *Validating
func (*Validating) Create ¶
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 ¶
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.