store

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 8 Imported by: 0

README

C4 Store

GoDoc

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

C4 store is a package for representing generic c4 storage. A C4 Store abstracts the details of data management allowing c4 data consumers and producers to store and retreave c4 identified data easily using the c4 id alone.

Examples of c4 stores include object storage, filesystems, archive files, databases, bittorrent networks, web service endpoints, etc. C4 stores are also useful for encapsulating processes like encryption, creating distributed copies, and on the fly validation.

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

Constants

This section is empty.

Variables

View Source
var ErrInvalidID = fmt.Errorf("c4 id does not match data")
View Source
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

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

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

func (f Folder) Remove(id c4.ID) 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.

func (*Logger) Create

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

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

func (*Logger) Open

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

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

func (*Logger) Remove

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

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

type LoggerFlags

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

type MAP

type MAP map[c4.ID]string

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

func NewMap

func NewMap(m map[c4.ID]string) MAP

func (MAP) Create

func (s MAP) 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 MAP store then an error of type `*os.PathError` is returned.

func (MAP) Delete

func (m MAP) Delete(id c4.ID)

func (MAP) Load

func (m MAP) Load(id c4.ID) (path string)

func (MAP) LoadOrStore

func (m MAP) LoadOrStore(id c4.ID, path string) (actual string, loaded bool)

func (MAP) Open

func (s MAP) 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 (MAP) Range

func (m MAP) Range(f func(id c4.ID, path string) bool)

func (MAP) Remove

func (s MAP) 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 RAM

type RAM map[c4.ID][]byte

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

func NewRAM

func NewRAM() *RAM

func (*RAM) Create

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

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

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

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

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

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.

func (*Validating) Remove

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

Jump to

Keyboard shortcuts

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