6 "github.com/anacrolix/squirrel"
7 "zombiezen.com/go/sqlite"
9 "github.com/anacrolix/torrent/metainfo"
10 "github.com/anacrolix/torrent/storage"
13 // A convenience function that creates a connection pool, resource provider, and a pieces storage
14 // ClientImpl and returns them all with a Close attached.
15 func NewDirectStorage(opts NewDirectStorageOpts) (_ storage.ClientImplCloser, err error) {
16 cache, err := squirrel.NewCache(opts)
26 func NewWrappingClient(cache *squirrel.Cache) storage.ClientImpl {
35 capacity func() (int64, bool)
38 func (c *client) OpenTorrent(*metainfo.Info, metainfo.Hash) (storage.TorrentImpl, error) {
40 return storage.TorrentImpl{Piece: t.Piece, Close: t.Close, Capacity: &c.capacity}, nil
47 func (t torrent) Piece(p metainfo.Piece) storage.PieceImpl {
49 sb: t.c.OpenWithLength(p.Hash().HexString(), p.Length()),
51 ret.ReaderAt = &ret.sb
52 ret.WriterAt = &ret.sb
56 func (t torrent) Close() error {
66 func (p piece) MarkComplete() error {
67 return p.sb.SetTag("verified", true)
70 func (p piece) MarkNotComplete() error {
71 return p.sb.SetTag("verified", false)
74 func (p piece) Completion() (ret storage.Completion) {
75 err := p.sb.GetTag("verified", func(stmt *sqlite.Stmt) {
76 ret.Complete = stmt.ColumnInt(0) != 0