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

36 lines
577 B
Go
Raw Permalink Normal View History

2014-08-21 19:24:23 -05:00
package storage
import (
"io"
"os"
)
2017-05-21 10:16:16 +00:00
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
2014-08-21 19:24:23 -05:00
}
type File interface {
io.ReadCloser
io.ReaderAt
io.Seeker
Stat() (fi os.FileInfo, err error)
}
2017-05-21 10:16:16 +00:00
func Init(path string) (Store, error) {
st := new(fsStore)
2014-08-21 19:24:23 -05:00
st.path = path
_, err := os.Stat(path)
if err != nil {
err = mkstore(st.path)
}
return st, err
}
2017-05-21 10:16:16 +00:00
func RO(st Store) Store {
return &roStore{st}
2014-08-21 19:24:23 -05:00
}