10 "github.com/anacrolix/squirrel"
12 "github.com/anacrolix/torrent/metainfo"
13 "github.com/anacrolix/torrent/storage"
16 // A convenience function that creates a connection pool, resource provider, and a pieces storage
17 // ClientImpl and returns them all with a Close attached.
18 func NewDirectStorage(opts NewDirectStorageOpts) (_ storage.ClientImplCloser, err error) {
19 cache, err := squirrel.NewCache(opts)
29 func NewWrappingClient(cache *squirrel.Cache) storage.ClientImpl {
38 capacity func() (int64, bool)
41 func (c *client) OpenTorrent(*metainfo.Info, metainfo.Hash) (storage.TorrentImpl, error) {
43 return storage.TorrentImpl{Piece: t.Piece, Close: t.Close, Capacity: &c.capacity}, nil
50 func (t torrent) Piece(p metainfo.Piece) storage.PieceImpl {
52 sb: t.c.OpenWithLength(p.Hash().HexString(), p.Length()),
54 ret.ReaderAt = &ret.sb
55 ret.WriterAt = &ret.sb
59 func (t torrent) Close() error {
69 func (p piece) MarkComplete() error {
70 return p.sb.SetTag("verified", true)
73 func (p piece) MarkNotComplete() error {
74 return p.sb.SetTag("verified", false)
77 func (p piece) Completion() (ret storage.Completion) {
78 err := p.sb.GetTag("verified", func(stmt *sqlite.Stmt) {
79 ret.Complete = stmt.ColumnInt(0) != 0