Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
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) // 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 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 ¶
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:
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
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: