Documentation ¶
Overview ¶
Package storage implements storage backends for package torrent.
Index ¶
- func CreateNativeZeroLengthFile(name string) error
- 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
- func NewBoltDB(filePath string) ClientImplCloser
- func NewFile(baseDir string) ClientImplCloser
- func NewFileByInfoHash(baseDir string) ClientImplCloser
- func NewFileOpts(opts NewFileClientOpts) ClientImplCloser
- func NewFileWithCompletion(baseDir string, completion PieceCompletion) ClientImplCloser
- func NewFileWithCustomPathMaker(baseDir string, ...) ClientImplCloserdeprecated
- func NewFileWithCustomPathMakerAndCompletion(baseDir string, pathMaker TorrentDirFilePathMaker, completion PieceCompletion) ClientImplCloserdeprecated
- func NewMMap(baseDir string) ClientImplCloser
- type Completion
- type ConsecutiveChunkReader
- type FileMapping
- type FilePathMaker
- type FilePathMakerOpts
- type NewFileClientOpts
- type Piece
- type PieceCompletion
- type PieceCompletionGetSetter
- type PieceImpl
- type PieceProvider
- type ResourcePiecesOpts
- type SelfHashing
- type SizedPutter
- type Torrent
- type TorrentCapacity
- type TorrentDirFilePathMaker
- 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 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 NewResourcePieces ¶
func NewResourcePieces(p PieceProvider) ClientImpl
func NewResourcePiecesOpts ¶ added in v1.22.0
func NewResourcePiecesOpts(p PieceProvider, opts ResourcePiecesOpts) 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. The info names of each torrent are used as directories.
func NewFileByInfoHash ¶
func NewFileByInfoHash(baseDir string) ClientImplCloser
File storage with data partitioned by infohash.
func NewFileOpts ¶ added in v1.31.0
func NewFileOpts(opts NewFileClientOpts) ClientImplCloser
NewFileOpts creates a new ClientImplCloser that stores files using the OS native filesystem.
func NewFileWithCompletion ¶
func NewFileWithCompletion(baseDir string, completion PieceCompletion) ClientImplCloser
func NewFileWithCustomPathMaker
deprecated
func NewFileWithCustomPathMaker(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string) ClientImplCloser
Deprecated: 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 NewFileWithCustomPathMakerAndCompletion
deprecated
added in
v1.27.0
func NewFileWithCustomPathMakerAndCompletion( baseDir string, pathMaker TorrentDirFilePathMaker, completion PieceCompletion, ) ClientImplCloser
Deprecated: Allows passing custom PieceCompletion
func NewMMap ¶
func NewMMap(baseDir string) ClientImplCloser
TODO: Support all the same native filepath configuration that NewFileOpts provides.
type Completion ¶
type ConsecutiveChunkReader ¶ added in v1.23.0
type ConsecutiveChunkReader interface {
ReadConsecutiveChunks(prefix string) (io.ReadCloser, error)
}
type FileMapping ¶ added in v1.52.0
func WrapFileMapping ¶ added in v1.52.0
func WrapFileMapping(region mmap.MMap, file *os.File) FileMapping
Combines a mmapped region and file into a storage Mmap abstraction, which handles closing the mmap file handle.
type FilePathMaker ¶ added in v1.31.0
type FilePathMaker func(opts FilePathMakerOpts) string
Determines the filepath to be used for each file in a torrent.
type FilePathMakerOpts ¶ added in v1.31.0
Info passed to a FilePathMaker.
type NewFileClientOpts ¶ added in v1.31.0
type NewFileClientOpts struct { // The base directory for all downloads. ClientBaseDir string FilePathMaker FilePathMaker TorrentDirMaker TorrentDirFilePathMaker PieceCompletion PieceCompletion }
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 NewDefaultPieceCompletionForDir ¶ added in v1.28.0
func NewDefaultPieceCompletionForDir(dir string) (PieceCompletion, error)
sqlite is always the default when available.
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. SelfHashing, such as when a piece supports a more efficient way to hash its contents.
type PieceProvider ¶ added in v1.19.0
type ResourcePiecesOpts ¶ added in v1.22.0
type ResourcePiecesOpts struct { // After marking a piece complete, don't bother deleting its incomplete blobs. LeaveIncompleteChunks bool // Sized puts require being able to stream from a statement executed on another connection. // Without them, we buffer the entire read and then put that. NoSizedPuts bool Capacity *int64 }
type SelfHashing ¶ added in v1.29.0
Allows a storage backend to override hashing (i.e. if it can do it more efficiently than the torrent client can)
type Torrent ¶
type Torrent struct {
TorrentImpl
}
type TorrentCapacity ¶ added in v1.32.0
type TorrentDirFilePathMaker ¶ added in v1.31.0
type TorrentDirFilePathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string
Determines the directory for a given torrent within a storage client.
type TorrentImpl ¶
type TorrentImpl struct { Piece func(p metainfo.Piece) PieceImpl Close func() error Flush func() error // Storages that share the same space, will provide equal pointers. The function is called once // to determine the storage for torrents sharing the same function pointer, and mutated in // place. Capacity TorrentCapacity }
Data storage bound to a torrent.