import (
"io"
- "crawshaw.io/sqlite"
"github.com/anacrolix/squirrel"
"github.com/anacrolix/torrent/metainfo"
}
return &client{
cache,
- cache.GetCapacity}, nil
+ cache.GetCapacity,
+ }, nil
+}
+
+func NewWrappingClient(cache *squirrel.Cache) storage.ClientImpl {
+ return &client{
+ cache,
+ cache.GetCapacity,
+ }
}
type client struct {
*squirrel.Cache
- capacity func() *int64
+ capacity func() (int64, bool)
}
-func (c *client) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (storage.TorrentImpl, error) {
+func (c *client) OpenTorrent(*metainfo.Info, metainfo.Hash) (storage.TorrentImpl, error) {
t := torrent{c.Cache}
return storage.TorrentImpl{Piece: t.Piece, Close: t.Close, Capacity: &c.capacity}, nil
}
func (t torrent) Piece(p metainfo.Piece) storage.PieceImpl {
ret := piece{
- sb: squirrel.Blob{
- p.Hash().HexString(),
- p.Length(),
- t.c,
- },
+ sb: t.c.OpenWithLength(p.Hash().HexString(), p.Length()),
}
ret.ReaderAt = &ret.sb
ret.WriterAt = &ret.sb
}
func (p piece) Completion() (ret storage.Completion) {
- err := p.sb.GetTag("verified", func(stmt *sqlite.Stmt) {
+ err := p.sb.GetTag("verified", func(stmt squirrel.SqliteStmt) {
ret.Complete = stmt.ColumnInt(0) != 0
})
ret.Ok = err == nil
- if err != nil {
- panic(err)
- }
+ ret.Err = err
return
}