torrent

package
v0.0.0-...-aea99ae Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Length int64    `bencode:"length"`
	Path   []string `bencode:"path"`
}

FileInfo represents a file in multi-file torrents

type InfoDict

type InfoDict struct {
	PieceLength int64  `bencode:"piece length"`
	Pieces      string `bencode:"pieces"`
	Private     int64  `bencode:"private,omitempty"`
	Name        string `bencode:"name"`

	// Single file mode
	Length int64 `bencode:"length,omitempty"`

	// Multi-file mode
	Files []FileInfo `bencode:"files,omitempty"`
}

InfoDict represents the info dictionary in a torrent file

func (*InfoDict) GetPieceHashes

func (i *InfoDict) GetPieceHashes() ([][20]byte, error)

GetPieceHashes returns the list of piece hashes

func (*InfoDict) IsSingleFile

func (i *InfoDict) IsSingleFile() bool

IsSingleFile returns true if this is a single-file torrent

func (*InfoDict) MarshalJSON

func (i *InfoDict) MarshalJSON() ([]byte, error)

MarshalJSON customizes JSON output for InfoDict

func (*InfoDict) TotalLength

func (i *InfoDict) TotalLength() int64

TotalLength returns the total size of the torrent

type MetaInfo

type MetaInfo struct {
	Announce     string     `bencode:"announce"`
	AnnounceList [][]string `bencode:"announce-list,omitempty"`
	Comment      string     `bencode:"comment,omitempty"`
	CreatedBy    string     `bencode:"created by,omitempty"`
	CreationDate int64      `bencode:"creation date,omitempty"`
	Info         InfoDict   `bencode:"info"`
	InfoHash     dht.Key    `bencode:"-"`
}

MetaInfo represents the complete torrent file structure

func Parse

func Parse(r io.Reader) (*MetaInfo, error)

Parse parses a torrent metainfo from a reader

func ParseMetadata

func ParseMetadata(metadata []byte, infoHash [20]byte) (*MetaInfo, error)

ParseMetadata parses metadata from raw bytes (used for BEP 9 metadata exchange)

func (*MetaInfo) GetTrackers

func (m *MetaInfo) GetTrackers() []string

GetTrackers returns all trackers from announce and announce-list

func (*MetaInfo) MarshalJSON

func (m *MetaInfo) MarshalJSON() ([]byte, error)

MarshalJSON customizes JSON output for MetaInfo

func (*MetaInfo) Write

func (m *MetaInfo) Write(w io.Writer) error

Write writes a torrent metainfo to a writer

Jump to

Keyboard shortcuts

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