Documentation ¶
Index ¶
- Constants
- type Deleter
- type Dir
- type File
- type Filer
- type Lister
- type Logstore
- type Opener
- type Ramstore
- func (rs *Ramstore) Delete(path string) error
- func (rs *Ramstore) List() []string
- func (rs *Ramstore) Mkdir(dir string) error
- func (rs *Ramstore) Open(name string) (File, error)
- func (rs *Ramstore) Root(name string) (Dir, error)
- func (rs *Ramstore) Type() string
- func (rs *Ramstore) Walk(name string) (any, error)
Examples ¶
Constants ¶
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 ¶
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) // 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 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
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:
type Opener ¶
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
RamStore is a type that implements Filer as an in-memory data store
func NewRamstore ¶ added in v0.2.5
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: