io

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package io contains the definition of the IO Provider, as well as various implementations of the concept.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = errors.New("already exists")

Error returned if data is found during a "Put" call.

View Source
var ErrNotFound = errors.New("not found")

Error returned if data is not found during a "Get" or "Update" call.

Functions

This section is empty.

Types

type Bolt

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

Mem implements an IO Provider backed by the key/value database bolt..

func NewBolt

func NewBolt(path string) (Bolt, error)

NewBolt creates a new IO Provider that stores its data in the specified file.

func (*Bolt) Delete

func (b *Bolt) Delete(_ context.Context, id []byte, dataType DataType) error

func (*Bolt) Get

func (b *Bolt) Get(_ context.Context, id []byte, dataType DataType) ([]byte, error)

func (*Bolt) Put

func (b *Bolt) Put(_ context.Context, id []byte, dataType DataType, data []byte) error

func (*Bolt) Update

func (b *Bolt) Update(_ context.Context, id []byte, dataType DataType, data []byte) error

type DataType

type DataType uint16

Types of data supported by an IO Provider.

const (
	DataTypeSealedObject DataType = iota
	DataTypeSealedAccess
	DataTypeSealedNode
	DataTypeEnd
)

func (DataType) Bytes

func (d DataType) Bytes() []byte

Bytes returns a byte representation of a DataType.

func (DataType) String

func (d DataType) String() string

String returns a string representation of a DataType.

type Mem

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

Mem implements an in-memory version of an IO Provider.

func NewMem

func NewMem() Mem

NewMem creates a new in-memory IO Provider.

func (*Mem) Delete

func (m *Mem) Delete(_ context.Context, id []byte, dataType DataType) error

func (*Mem) Get

func (m *Mem) Get(_ context.Context, id []byte, dataType DataType) ([]byte, error)

func (*Mem) Put

func (m *Mem) Put(_ context.Context, id []byte, dataType DataType, data []byte) error

func (*Mem) Update

func (m *Mem) Update(_ context.Context, id []byte, dataType DataType, data []byte) error

type Provider

type Provider interface {
	// Put sends bytes to the IO Provider. The data is identified by an ID and a data type.
	// Should return ErrAlreadyExists if the data already exists in the IO Provider.
	Put(ctx context.Context, id []byte, dataType DataType, data []byte) error

	// Get fetches data from the IO Provider. The data is identified by an ID and a data type.
	// Should return ErrNotFound if the data does not exist in the IO Provider.
	Get(ctx context.Context, id []byte, dataType DataType) ([]byte, error)

	// Update is similar to Put but updates data previously sent to the IO Provider.
	// Should return ErrNotFound if the data does not exist in the IO Provider.
	Update(ctx context.Context, id []byte, dataType DataType, data []byte) error

	// Delete removes data previously sent to the IO Provider.
	// Should not error if the data does not exist in the IO Provider.
	Delete(ctx context.Context, id []byte, dataType DataType) error
}

Provider is the interface an IO Provider must implement to handle data from D1.

type Proxy

type Proxy struct {
	Implementation Provider
	PutFunc        func(ctx context.Context, id []byte, dataType DataType, data []byte) error
	GetFunc        func(ctx context.Context, id []byte, dataType DataType) ([]byte, error)
	UpdateFunc     func(ctx context.Context, id []byte, dataType DataType, data []byte) error
	DeleteFunc     func(ctx context.Context, id []byte, dataType DataType) error
}

Proxy is an IO Provider that wraps other IO Providers By default, it forwards calls directly to the implementation, but allows you to customize the behavior as you see fit by changing the individual functions as you see fit.

func NewProxy

func NewProxy(implementation Provider) Proxy

NewProxy returns a basic implementation of Proxy that can be used as a basis for tests.

func (*Proxy) Delete

func (o *Proxy) Delete(ctx context.Context, id []byte, dataType DataType) error

func (*Proxy) Get

func (o *Proxy) Get(ctx context.Context, id []byte, dataType DataType) ([]byte, error)

func (*Proxy) Put

func (o *Proxy) Put(ctx context.Context, id []byte, dataType DataType, data []byte) error

func (*Proxy) Update

func (o *Proxy) Update(ctx context.Context, id []byte, dataType DataType, data []byte) error

Jump to

Keyboard shortcuts

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