store

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPadding added in v1.0.45

func IsPadding(f metainfo.FileInfo) bool

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.

func Paths

func Paths(base string, info *metainfo.Info) ([]string, error)

Paths returns the on-disk location of every file of the torrent, in torrent order.

func RootName added in v1.0.46

func RootName(info *metainfo.Info) string

RootName is the name of the torrent's own folder, or of its one file, on the disk: its name made fit for the system (see safeName). It is "" for a torrent without a folder of its own (metainfo.NoName), whose files lie right in the save folder.

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

func NewResolver(baseFor func(metainfo.Hash) string, comp storage.PieceCompletion) *Storage

NewResolver creates a storage whose directory is decided per torrent.

func (*Storage) BlockFiles

func (s *Storage) BlockFiles(ih metainfo.Hash, paths []string) (unblock func())

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

func (s *Storage) CloseFiles(ih metainfo.Hash, paths []string)

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

func (s *Storage) DropParts(ih metainfo.Hash)

DropParts deletes the part file of a torrent (it is being removed).

func (*Storage) FilesChanged added in v1.0.42

func (s *Storage) FilesChanged(ih metainfo.Hash) error

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

func (s *Storage) HasParts(ih metainfo.Hash) bool

HasParts tells whether a torrent has a part file (whether it is open or not).

func (*Storage) InParts added in v1.0.42

func (s *Storage) InParts(ih metainfo.Hash) []bool

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

func (s *Storage) OnMissingFile(f func(metainfo.Hash))

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 (s *Storage) OpenTorrent(_ context.Context, info *metainfo.Info, ih metainfo.Hash) (storage.TorrentImpl, error)

func (*Storage) Restat added in v1.0.47

func (s *Storage) Restat(ih metainfo.Hash)

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.

func (*Storage) Trust

func (s *Storage) Trust(ih metainfo.Hash)

Trust makes the next opening of the torrent take the files that are already on disk, at full size, as finished without hashing them ("skip the hash check"). It applies once.

func (*Storage) UseParts added in v1.0.42

func (s *Storage) UseParts(dir string, skipped func(metainfo.Hash) []bool)

UseParts turns the part file on: dir is where the part files live, skipped tells which files of a torrent are marked "do not download" (by index; a missing entry means wanted).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL