Documentation
¶
Overview ¶
Package torrentfs exposes a torrent client as a read-only filesystem.
It is FUSE-library-agnostic: the core types (TorrentFS, Backend, Unmounter) and helpers live here; concrete FUSE backends are in separate modules:
- github.com/anacrolix/og-torrentfs – uses github.com/anacrolix/fuse
- github.com/anacrolix/hanwen-torrentfs – uses github.com/hanwen/go-fuse/v2
Filesystem traversal ¶
traverse.go provides the directory-listing and lookup helpers used by every backend:
- RootEntries / RootLookup – enumerate/find top-level torrent entries
- DirEntries / DirLookup – enumerate/find entries inside a torrent directory
File reading ¶
fileread.go provides ReadFile, which reads a range of bytes from a torrent file. It blocks until data is available, the context is cancelled, or Destroy is called on the TorrentFS.
io/fs ¶
iofs.go provides TorrentFS.IOFS, a read-only io/fs.FS built on the same helpers, for access to torrent data without FUSE.
Testing ¶
The tfstest sub-package contains a shared integration test suite (RunTestSuite) that any backend can run against its MountFunc. The same suite runs in this module against TorrentFS.IOFS via RunFSTestSuite, so the shared helpers are tested without FUSE.
Index ¶
- Variables
- func IsSubPath(parent, child string) bool
- func ReadFile(ctx context.Context, tfs *TorrentFS, f *torrent.File, dest []byte, off int64) (int, error)
- type Backend
- type DirEntry
- type TorrentFS
- func (tfs *TorrentFS) Destroy()
- func (tfs *TorrentFS) Destroyed() <-chan struct{}
- func (tfs *TorrentFS) IOFS() fs.FS
- func (tfs *TorrentFS) Mount(mountDir string, b Backend) (Unmounter, error)
- func (tfs *TorrentFS) TrackBlockedRead() (done func())
- func (tfs *TorrentFS) WaitBlockedReads(ctx context.Context, n int)
- type TorrentLookup
- type Unmounter
Constants ¶
This section is empty.
Variables ¶
var ErrDestroyed = errors.New("torrentfs: filesystem destroyed")
ErrDestroyed is returned by ReadFile when the filesystem has been destroyed.
Functions ¶
func ReadFile ¶ added in v1.62.0
func ReadFile(ctx context.Context, tfs *TorrentFS, f *torrent.File, dest []byte, off int64) (int, error)
ReadFile reads len(dest) bytes at offset off from torrent file f. It blocks until data is available, the context is cancelled, or the filesystem is destroyed. It returns (n, ErrDestroyed) if the filesystem is destroyed, (n, ctx.Err()) if the context is cancelled, or (n, nil) on success.
Types ¶
type Backend ¶ added in v1.62.0
Backend is implemented by FUSE library integrations (e.g. hanwen-torrentfs, og-torrentfs). It mounts a TorrentFS at a directory and returns an Unmounter.
type DirEntry ¶ added in v1.62.0
DirEntry describes a single filesystem entry returned by a directory listing.
func DirEntries ¶ added in v1.62.0
DirEntries returns directory entries for a sub-directory at path within t.
func RootEntries ¶ added in v1.62.0
RootEntries returns directory entries for the root of tfs.
type TorrentFS ¶
TorrentFS is the shared state for a torrent-backed filesystem. It holds no FUSE-library-specific code; mount it via a Backend.
func (*TorrentFS) Destroy ¶
func (tfs *TorrentFS) Destroy()
Destroy signals all blocked reads to abort and marks the FS as destroyed.
func (*TorrentFS) Destroyed ¶ added in v1.62.0
func (tfs *TorrentFS) Destroyed() <-chan struct{}
Destroyed returns a channel that is closed when Destroy is called.
func (*TorrentFS) IOFS ¶ added in v1.63.0
IOFS returns a read-only io/fs.FS view of tfs. It is built on the same traversal and read helpers as the FUSE backends, so it can be used to access torrent data without FUSE (for example with http.FileServerFS), and to run the tfstest suite without mounting anything.
Reads block until the data is available, the file is closed, or tfs is destroyed. Files implement io.ReaderAt and io.Seeker; directories implement fs.ReadDirFile.
func (*TorrentFS) TrackBlockedRead ¶ added in v1.62.0
func (tfs *TorrentFS) TrackBlockedRead() (done func())
TrackBlockedRead is called by backend read implementations when they block waiting for torrent data. The returned func must be called when the read completes or is cancelled.
type TorrentLookup ¶ added in v1.62.0
type TorrentLookup struct {
IsDir bool
Torrent *torrent.Torrent
File *torrent.File // nil when IsDir is true
Path string // full path within the torrent
}
TorrentLookup is the result of a successful lookup in a torrent filesystem.
func DirLookup ¶ added in v1.62.0
func DirLookup(t *torrent.Torrent, path, name string) (TorrentLookup, bool)
DirLookup looks up name in the sub-directory at path within torrent t.
func RootLookup ¶ added in v1.62.0
func RootLookup(tfs *TorrentFS, name string) (TorrentLookup, bool)
RootLookup looks up name in the root of tfs.