Package storage implements storage backends for package torrent.



    This section is empty.


    This section is empty.


    func CreateNativeZeroLengthFile

    func CreateNativeZeroLengthFile(name string) error

      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 NewSqlitePieceCompletion

      func NewSqlitePieceCompletion(dir string) (ret *sqlitePieceCompletion, err error)

      func ToSafeFilePath

      func ToSafeFilePath(fileInfoComponents ...string) (string, error)

        Combines file info path components, ensuring the result won't escape into parent directories.


        type Client

        type Client struct {
        	// contains filtered or unexported fields

        func NewClient

        func NewClient(cl ClientImpl) *Client

        func (Client) OpenTorrent

        func (cl Client) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (*Torrent, error)

        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

              func NewResourcePiecesOpts

              func NewResourcePiecesOpts(p PieceProvider, opts ResourcePiecesOpts) ClientImpl

              type ClientImplCloser

              type ClientImplCloser interface {
              	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 Completion struct {
                	Complete bool
                	Ok       bool

                type ConsecutiveChunkReader

                type ConsecutiveChunkReader interface {
                	ReadConsecutiveChunks(prefix string) (io.ReadCloser, error)

                type Piece

                type Piece struct {
                	// contains filtered or unexported fields

                func (Piece) ReadAt

                func (p Piece) ReadAt(b []byte, off int64) (n int, err error)

                func (Piece) WriteAt

                func (p Piece) WriteAt(b []byte, off int64) (n int, err error)

                func (Piece) WriteTo

                func (p Piece) WriteTo(w io.Writer) (int64, error)

                  Why do we have this wrapper? Well PieceImpl doesn't implement io.Reader, so we can't let io.Copy and friends check for io.WriterTo and fallback for us since they expect an io.Reader.

                  type PieceCompletion

                  type PieceCompletion interface {
                  	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 PieceCompletionGetSetter

                    type PieceCompletionGetSetter interface {
                    	Get(metainfo.PieceKey) (Completion, error)
                    	Set(_ metainfo.PieceKey, complete bool) error

                    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.
                    	// 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

                      type PieceProvider interface {

                      type ResourcePiecesOpts

                      type ResourcePiecesOpts struct {
                      	LeaveIncompleteChunks bool
                      	NoSizedPuts           bool

                      type SizedPutter

                      type SizedPutter interface {
                      	PutSized(io.Reader, int64) error

                      type Torrent

                      type Torrent struct {

                      func (Torrent) Piece

                      func (t Torrent) Piece(p metainfo.Piece) Piece

                      type TorrentImpl

                      type TorrentImpl interface {
                      	Piece(metainfo.Piece) PieceImpl
                      	Close() error

                        Data storage bound to a torrent.


                        Path Synopsis