Use io.readerAt to open the books without loading everything in memory

This commit is contained in:
Las Zenow 2015-01-22 21:16:20 -06:00
parent 965205adae
commit e732909773
2 changed files with 45 additions and 27 deletions

View file

@ -11,6 +11,12 @@ type Store struct {
path string
}
type File interface {
io.ReadCloser
io.ReaderAt
Stat() (fi os.FileInfo, err error)
}
func Init(path string) (*Store, error) {
st := new(Store)
st.path = path
@ -42,7 +48,7 @@ func (st *Store) Store(id string, file io.Reader, name string) (size int64, err
return io.Copy(dest, file)
}
func (st *Store) Get(id string, name string) (io.ReadCloser, error) {
func (st *Store) Get(id string, name string) (File, error) {
path := idPath(st.path, id)
return os.Open(p.Join(path, name))
}