Documentation ¶
Overview ¶
Package storage implements storage backends for package torrent.
Index ¶
- func CreateNativeZeroLengthFile(name string) error
- func NewFileWithCompletion(baseDir string, completion PieceCompletion) *fileClientImpl
- func NewMMapWithCompletion(baseDir string, completion PieceCompletion) *mmapClientImpl
- func NewSqlitePieceCompletion(dir string) (ret *sqlitePieceCompletion, err error)
- func ToSafeFilePath(fileInfoComponents ...string) (string, error)
- type Client
- type ClientImpl
- type ClientImplCloser
- type Completion
- type ConsecutiveChunkWriter
- type Piece
- type PieceCompletion
- type PieceCompletionGetSetter
- type PieceImpl
- type PieceProvider
- type Torrent
- type TorrentImpl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateNativeZeroLengthFile ¶ added in v1.18.0
A helper to create zero-length files which won't appear for file-orientated storage since no writes will ever occur to them (no torrent data is associated with a zero-length file). The caller should make sure the file name provided is safe/sanitized.
func NewFileWithCompletion ¶
func NewFileWithCompletion(baseDir string, completion PieceCompletion) *fileClientImpl
func NewMMapWithCompletion ¶
func NewMMapWithCompletion(baseDir string, completion PieceCompletion) *mmapClientImpl
func ToSafeFilePath ¶ added in v1.18.0
Combines file info path components, ensuring the result won't escape into parent directories.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(cl ClientImpl) *Client
type ClientImpl ¶
type ClientImpl interface {
OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error)
}
Represents data storage for an unspecified torrent.
func NewFileByInfoHash ¶
func NewFileByInfoHash(baseDir string) ClientImpl
File storage with data partitioned by infohash.
func NewFileWithCustomPathMaker ¶
func NewFileWithCustomPathMaker(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string) ClientImpl
Allows passing a function to determine the path for storing torrent data. The function is responsible for sanitizing the info if it uses some part of it (for example sanitizing info.Name).
func NewResourcePieces ¶
func NewResourcePieces(p PieceProvider) ClientImpl
type ClientImplCloser ¶ added in v1.15.0
type ClientImplCloser interface { ClientImpl Close() error }
func NewBoltDB ¶
func NewBoltDB(filePath string) ClientImplCloser
func NewFile ¶
func NewFile(baseDir string) ClientImplCloser
All Torrent data stored in this baseDir
func NewMMap ¶
func NewMMap(baseDir string) ClientImplCloser
type Completion ¶
type ConsecutiveChunkWriter ¶ added in v1.19.0
type PieceCompletion ¶
type PieceCompletion interface { PieceCompletionGetSetter Close() error }
Implementations track the completion of pieces. It must be concurrent-safe.
func NewBoltPieceCompletion ¶
func NewBoltPieceCompletion(dir string) (ret PieceCompletion, err error)
func NewMapPieceCompletion ¶
func NewMapPieceCompletion() PieceCompletion
type PieceImpl ¶
type PieceImpl interface { // These interfaces are not as strict as normally required. They can // assume that the parameters are appropriate for the dimensions of the // piece. io.ReaderAt io.WriterAt // 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. MarkComplete() error MarkNotComplete() error // Returns true if the piece is complete. Completion() Completion }
Interacts with torrent piece data. Optional interfaces to implement include io.WriterTo, such as when a piece supports a more efficient way to write out incomplete chunks
type PieceProvider ¶ added in v1.19.0
type Torrent ¶
type Torrent struct {
TorrentImpl
}