store

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const (
	ErrInvalidTrunc = ramstore.ErrInvalidTrunc
	ErrShortSeek    = ramstore.ErrShortSeek
	ErrDirExists    = ramstore.ErrDirExists
	ErrFileClosed   = ramstore.ErrFileClosed
)

Forward errors from internal

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 Dir added in v0.2.5

type Dir interface {
	// Readdir returns an array of fs.FileInfo types to create a direntry
	Readdir(n int) ([]fs.FileInfo, error)
	Info() (fs.FileInfo, error)
}

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)
	// 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
	Mkdir(string) error
	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 added in v0.2.5

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

We need to include streamer on this

func NewLogstore added in v0.2.5

func NewLogstore(base string, debug bool) *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, false)
	f, err := rs.Open("test/main")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

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

func (*Logstore) Delete added in v0.2.5

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

func (*Logstore) List added in v0.2.5

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

func (*Logstore) Mkdir added in v0.2.5

func (ls *Logstore) Mkdir(name string) error

func (*Logstore) Open added in v0.2.5

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

func (*Logstore) Root added in v0.2.5

func (ls *Logstore) Root(name string) (Dir, error)

TODO: Logdir's Root currently doesn't show our main/feed entry

func (*Logstore) Type added in v0.2.5

func (ls *Logstore) Type() string

type Opener

type Opener interface {
	Open(string) (File, error)
	Root(current string) (Dir, 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 added in v0.2.5

type Ramstore struct {
	Base *ramstore.Dir
}

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

func NewRamstore added in v0.2.5

func NewRamstore(debug bool) *Ramstore
Example
package main

import (
	"log"

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

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

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

func (*Ramstore) Delete added in v0.2.5

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

func (*Ramstore) List added in v0.2.5

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

func (*Ramstore) Mkdir added in v0.2.5

func (rs *Ramstore) Mkdir(dir string) error

func (*Ramstore) Open added in v0.2.5

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

func (*Ramstore) Root added in v0.2.5

func (rs *Ramstore) Root(name string) (Dir, error)

func (*Ramstore) Type added in v0.2.5

func (rs *Ramstore) Type() string

func (*Ramstore) Walk added in v0.2.5

func (rs *Ramstore) Walk(name string) (any, error)

Returns a dir or file, or any errors encountered

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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