Documentation
¶
Overview ¶
Package store is the torrent file storage. It replaces the engine's default storage, which memory-maps files and keeps them mapped until shutdown: on Windows that makes it impossible to delete or move a downloaded file while the daemon runs. Here every file is opened on demand, cached briefly and closed when idle or when the torrent is dropped.
Index ¶
- func IsPadding(f metainfo.FileInfo) bool
- func Paths(base string, info *metainfo.Info) ([]string, error)
- func RootName(info *metainfo.Info) string
- type Storage
- func (s *Storage) BlockFiles(ih metainfo.Hash, paths []string) (unblock func())
- func (s *Storage) CloseFiles(ih metainfo.Hash, paths []string)
- func (s *Storage) DropParts(ih metainfo.Hash)
- func (s *Storage) FilesChanged(ih metainfo.Hash) error
- func (s *Storage) HasParts(ih metainfo.Hash) bool
- func (s *Storage) InParts(ih metainfo.Hash) []bool
- func (s *Storage) OnMissingFile(f func(metainfo.Hash))
- func (s *Storage) OpenTorrent(_ context.Context, info *metainfo.Info, ih metainfo.Hash) (storage.TorrentImpl, error)
- func (s *Storage) Restat(ih metainfo.Hash)
- func (s *Storage) Trust(ih metainfo.Hash)
- func (s *Storage) UseParts(dir string, skipped func(metainfo.Hash) []bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPadding ¶ added in v1.0.45
IsPadding tells whether a file of a torrent is a padding file (BEP 47, the "p" attribute): zeros that only align the next file to a piece. It is not written to the disk and not shown.
Types ¶
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage implements storage.ClientImpl. Files live at <base>/<torrent name>/<path>, where base is chosen per torrent.
func New ¶
func New(base string, comp storage.PieceCompletion) *Storage
New creates a storage that keeps every torrent under one directory; comp remembers which pieces are verified (may be nil).
func NewResolver ¶
NewResolver creates a storage whose directory is decided per torrent.
func (*Storage) BlockFiles ¶
BlockFiles makes the given files of a torrent unreachable for the engine until the returned function is called: reads fail as if the file was missing and writes are dropped, and the open handles are closed as soon as nobody uses them. It is how a file is deleted while the torrent is being checked or is downloading: without it the engine opens the file again at once and the deletion fails with "used by another process".
func (*Storage) CloseFiles ¶
CloseFiles closes the open handles of the given files of a torrent (a handle that is in use goes on the moment it is free), so that the files can be deleted or moved at once instead of after the idle timeout.
func (*Storage) DropParts ¶ added in v1.0.42
DropParts deletes the part file of a torrent (it is being removed).
func (*Storage) FilesChanged ¶ added in v1.0.42
FilesChanged is called when the files a torrent skips have changed: the files that are wanted again get their bytes from the part file.
func (*Storage) HasParts ¶ added in v1.0.42
HasParts tells whether a torrent has a part file (whether it is open or not).
func (*Storage) InParts ¶ added in v1.0.42
InParts tells, by index, which files of an open torrent are kept in its part file (nil when there are none).
func (*Storage) OnMissingFile ¶ added in v1.0.47
OnMissingFile sets what is called when the engine reads a piece and a file it lies in is not on the disk (deleted or taken away by hand): the engine itself only refuses the peer that asked and goes on as if nothing happened. It is called on the engine's reading goroutine and must not block. Set it before any torrent is opened.
func (*Storage) OpenTorrent ¶
func (*Storage) Restat ¶ added in v1.0.47
Restat reads the sizes of a torrent's files from the disk again, as at its opening, and forgets the "complete" records of the pieces whose files are not there any more (see Completion): after files were deleted or taken away by hand, the engine, asked about those pieces again, learns that they are gone. It also comes before a check of files that were put back, which would otherwise find the sizes of when they were missing.