Fix OpenBook from GridFS
This commit is contained in:
parent
f075f666ad
commit
6971028b9e
1 changed files with 7 additions and 17 deletions
24
store.go
24
store.go
|
@ -1,9 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"git.gitorious.org/go-pkg/epubgo.git"
|
"git.gitorious.org/go-pkg/epubgo.git"
|
||||||
"io"
|
"io"
|
||||||
"labix.org/v2/mgo"
|
"io/ioutil"
|
||||||
"labix.org/v2/mgo/bson"
|
"labix.org/v2/mgo/bson"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -63,27 +64,16 @@ func ParseFile(id bson.ObjectId) (string, error) {
|
||||||
|
|
||||||
func OpenBook(id bson.ObjectId) (*epubgo.Epub, error) {
|
func OpenBook(id bson.ObjectId) (*epubgo.Epub, error) {
|
||||||
fs := db.GetFS(FS_BOOKS)
|
fs := db.GetFS(FS_BOOKS)
|
||||||
var reader readerGrid
|
f, err := fs.OpenId(id)
|
||||||
var err error
|
|
||||||
reader.f, err = fs.OpenId(id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer reader.f.Close()
|
defer f.Close()
|
||||||
return epubgo.Load(reader, reader.f.Size())
|
|
||||||
}
|
|
||||||
|
|
||||||
type readerGrid struct {
|
buff, err := ioutil.ReadAll(f)
|
||||||
f *mgo.GridFile
|
reader := bytes.NewReader(buff)
|
||||||
}
|
|
||||||
|
|
||||||
func (r readerGrid) ReadAt(p []byte, off int64) (n int, err error) {
|
return epubgo.Load(reader, int64(len(buff)))
|
||||||
_, err = r.f.Seek(off, 0)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.f.Read(p)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func StoreNewFile(name string, file io.Reader) (bson.ObjectId, error) {
|
func StoreNewFile(name string, file io.Reader) (bson.ObjectId, error) {
|
||||||
|
|
Reference in a new issue