store

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deleter

type Deleter interface {
	Delete(string) error
}

Deleter removes a single File item from the storage by name If the file does not exist, has active Streams, or has not been correctly closed, an error is returned

type File

type File interface {
	// Read reads up to len(b) bytes from the File and stores them in b. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.
	Read(b []byte) (n int, err error)
	//Write writes len(b) bytes from b to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).
	Write(p []byte) (n int, err error)
	// Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any.
	Seek(offset int64, whence int) (int64, error)
	// Close closes the File, rendering it unusable for I/O. On files that support SetDeadline, any pending I/O operations will be canceled and return immediately with an ErrClosed error. Close will return an error if it has already been called.
	Close() error
	// Name returns the internal pathname of the File
	Name() string
	// Stat returns a FileInfo for the File, useful with some listener implementations
	Stat() (fs.FileInfo, error)
	// Stream ReadCloser that can be used to read bytes in a continuous manner
	// Each call to stream will get a copy of what has been written to the file
	// All further reads will block until there is new data, or Close() is called
	Stream() (io.ReadCloser, error)
	// Truncate limits the size of the file to the given int64 value
	Truncate(int64) error
}

File is an interface which represents data for a single file This is extended over the typical io/fs File, with a Write method

type Filer

type Filer interface {
	Lister
	Opener
	Deleter
	Type() string
}

Filer is an interface that is required for the Listeners to have access to data

type Lister

type Lister interface {
	List() []string
}

Lister returns an array of paths available on the storage These can be accessed with an Open command, given the same path

type LogStore

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

We need to include streamer on this

func NewLogStore

func NewLogStore(base string) *LogStore
Example
package main

import (
	"log"
	"os"

	"github.com/altid/libs/store"
)

func main() {
	tmp, err := os.MkdirTemp("", "altid")
	if err != nil {
		log.Fatal(err)
	}
	rs := store.NewLogStore(tmp)
	f, err := rs.Open("test/main")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	f.Write([]byte("Some data"))
}
Output:

func (*LogStore) Delete

func (ls *LogStore) Delete(name string) error

func (*LogStore) List

func (ls *LogStore) List() []string

func (*LogStore) Open

func (ls *LogStore) Open(name string) (File, error)

func (*LogStore) Root added in v0.2.2

func (ls *LogStore) Root(name string) (File, error)

func (*LogStore) Type added in v0.2.2

func (ls *LogStore) Type() string

type Opener

type Opener interface {
	Open(string) (File, error)
	Root(current string) (File, error)
}

Opener returns a single File item from the storage by name If the file does not exist, it is created and returned Files returned by an Opener should be closed with Close() after Root returns the root directory, which on read returns the filestats for files in the root directory such as "/errors" and "/tabs", and anything in the "/current" buffer will be returned as top-level overlay, such as "/current/main" --> "/main"

type RamStore

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

RamStore is a type that implements Filer as an in-memory data store

func NewRamStore

func NewRamStore() *RamStore
Example
package main

import (
	"log"

	"github.com/altid/libs/store"
)

func main() {
	rs := store.NewRamStore()
	f, err := rs.Open("testfile")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	f.Write([]byte("Some data"))
}
Output:

func (*RamStore) Delete

func (rs *RamStore) Delete(path string) error

func (*RamStore) List

func (rs *RamStore) List() []string

func (*RamStore) Open

func (rs *RamStore) Open(name string) (File, error)

func (*RamStore) Root added in v0.2.2

func (rs *RamStore) Root(name string) (File, error)

func (*RamStore) Type added in v0.2.2

func (rs *RamStore) Type() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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