9 "github.com/anacrolix/squirrel"
11 "github.com/anacrolix/torrent/metainfo"
12 "github.com/anacrolix/torrent/storage"
15 // A convenience function that creates a connection pool, resource provider, and a pieces storage
16 // ClientImpl and returns them all with a Close attached.
17 func NewDirectStorage(opts NewDirectStorageOpts) (_ storage.ClientImplCloser, err error) {
18 cache, err := squirrel.NewCache(opts)
28 func NewWrappingClient(cache *squirrel.Cache) storage.ClientImpl {
37 capacity func() (int64, bool)
40 func (c *client) OpenTorrent(*metainfo.Info, metainfo.Hash) (storage.TorrentImpl, error) {
42 return storage.TorrentImpl{Piece: t.Piece, Close: t.Close, Capacity: &c.capacity}, nil
49 func (t torrent) Piece(p metainfo.Piece) storage.PieceImpl {
51 sb: t.c.OpenWithLength(p.Hash().HexString(), p.Length()),
53 ret.ReaderAt = &ret.sb
54 ret.WriterAt = &ret.sb
58 func (t torrent) Close() error {
68 func (p piece) MarkComplete() error {
69 return p.sb.SetTag("verified", true)
72 func (p piece) MarkNotComplete() error {
73 return p.sb.SetTag("verified", false)
76 func (p piece) Completion() (ret storage.Completion) {
77 err := p.sb.GetTag("verified", func(stmt squirrel.SqliteStmt) {
78 ret.Complete = stmt.ColumnInt(0) != 0