localstore

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

ErrAlreadyExists returns the content exists.

TODO(weifu): move it into common pkg.

Functions

This section is empty.

Types

type Reader

type Reader interface {
	io.ReaderAt
	io.ReadCloser
	Size() int64
}

Reader extends io.ReadCloser interface with io.ReaderAt and reporting of Size.

type Store

type Store struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Store is a filesystem-like key/value storage.

Each key/value has committed and ingesting status. When OpenWriter returns ingestion transcation, the Store opens rootDir/ingest/$random file to receive value data. Once all the data is written, the Commit(ref) moves the file into rootDir/data/ref.

func NewStore

func NewStore(rootDir string) (*Store, error)

NewStore returns new instance of Store.

func (*Store) Delete

func (s *Store) Delete(ref string) error

Delete is to delete committed content named by ref.

func (*Store) OpenReader

func (s *Store) OpenReader(ref string) (Reader, error)

OpenReader is to open committed content named by ref.

func (*Store) OpenWriter

func (s *Store) OpenWriter() (Writer, error)

OpenWriter is to initiate a writing operation, ingestion transcation. A single ingestion transcation is to open temporary file and allow caller to write data into the temporary file. Once all the data is written, the caller should call Commit to complete ingestion transcation.

type Writer

type Writer interface {
	// Close closes the writer.
	//
	// If the writer has not been committed, this allows aborting.
	// Calling Close on a closed writer will not error.
	io.WriteCloser

	// Commit commits data as file named by ref.
	//
	// Commit always close Writer. If ref already exists, it will return
	// error.
	Commit(ref string) error
}

Writer handles writing of content into local store

Jump to

Keyboard shortcuts

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