2016-03-28 09:38:30 +00:00
|
|
|
package storage
|
2015-10-01 14:09:04 +00:00
|
|
|
|
2016-03-28 09:38:30 +00:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
2015-10-01 14:09:04 +00:00
|
|
|
|
2016-03-28 11:40:29 +00:00
|
|
|
// Represents data storage for an unspecified torrent.
|
2016-05-16 11:50:43 +00:00
|
|
|
type Client interface {
|
2016-03-28 11:40:29 +00:00
|
|
|
OpenTorrent(info *metainfo.InfoEx) (Torrent, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data storage bound to a torrent.
|
|
|
|
type Torrent interface {
|
2016-03-28 09:38:30 +00:00
|
|
|
Piece(metainfo.Piece) Piece
|
2016-03-28 11:40:29 +00:00
|
|
|
Close() error
|
2016-03-28 09:38:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 11:40:29 +00:00
|
|
|
// Interacts with torrent piece data.
|
2016-03-28 09:38:30 +00:00
|
|
|
type Piece interface {
|
2016-03-26 07:27:28 +00:00
|
|
|
// Should return io.EOF only at end of torrent. Short reads due to missing
|
|
|
|
// data should return io.ErrUnexpectedEOF.
|
2015-10-03 14:22:46 +00:00
|
|
|
io.ReaderAt
|
|
|
|
io.WriterAt
|
2016-03-26 07:27:28 +00:00
|
|
|
// Called when the client believes the piece data will pass a hash check.
|
|
|
|
// The storage can move or mark the piece data as read-only as it sees
|
|
|
|
// fit.
|
2016-03-28 09:38:30 +00:00
|
|
|
MarkComplete() error
|
2015-10-01 14:09:04 +00:00
|
|
|
// Returns true if the piece is complete.
|
2016-03-28 09:38:30 +00:00
|
|
|
GetIsComplete() bool
|
2015-10-01 14:09:04 +00:00
|
|
|
}
|