This repository has been archived on 2025-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
trantor/lib/storage/storage.go
2020-12-10 15:43:18 +00:00

35 lines
577 B
Go

package storage
import (
"io"
"os"
)
type Store interface {
Create(id string, name string) (io.WriteCloser, error)
Store(id string, file io.Reader, name string) (size int64, err error)
Get(id string, name string) (File, error)
Delete(id string) error
}
type File interface {
io.ReadCloser
io.ReaderAt
io.Seeker
Stat() (fi os.FileInfo, err error)
}
func Init(path string) (Store, error) {
st := new(fsStore)
st.path = path
_, err := os.Stat(path)
if err != nil {
err = mkstore(st.path)
}
return st, err
}
func RO(st Store) Store {
return &roStore{st}
}