torrent: github.com/anacrolix/torrent/metainfo Index | Files

package metainfo

import "github.com/anacrolix/torrent/metainfo"

Index

Package Files

announcelist.go fileinfo.go hash.go info.go magnet.go metainfo.go nodes.go piece.go piece_key.go pieces.go urllist.go

Constants

const HashSize = 20

func GeneratePieces Uses

func GeneratePieces(r io.Reader, pieceLength int64, b []byte) ([]byte, error)

type AnnounceList Uses

type AnnounceList [][]string

func (AnnounceList) Clone Uses

func (al AnnounceList) Clone() (ret AnnounceList)

func (AnnounceList) DistinctValues Uses

func (al AnnounceList) DistinctValues() (ret map[string]struct{})

func (AnnounceList) OverridesAnnounce Uses

func (al AnnounceList) OverridesAnnounce(announce string) bool

Whether the AnnounceList should be preferred over a single URL announce.

type FileInfo Uses

type FileInfo struct {
    Length   int64    `bencode:"length"` // BEP3
    Path     []string `bencode:"path"`   // BEP3
    PathUTF8 []string `bencode:"path.utf-8,omitempty"`
}

Information specific to a single file inside the MetaInfo structure.

func (*FileInfo) DisplayPath Uses

func (fi *FileInfo) DisplayPath(info *Info) string

func (FileInfo) Offset Uses

func (me FileInfo) Offset(info *Info) (ret int64)

type Hash Uses

type Hash [HashSize]byte

20-byte SHA1 hash used for info and pieces.

func HashBytes Uses

func HashBytes(b []byte) (ret Hash)

func NewHashFromHex Uses

func NewHashFromHex(s string) (h Hash)

func (Hash) AsString Uses

func (h Hash) AsString() string

func (Hash) Bytes Uses

func (h Hash) Bytes() []byte

func (*Hash) FromHexString Uses

func (h *Hash) FromHexString(s string) (err error)

func (Hash) HexString Uses

func (h Hash) HexString() string

func (Hash) String Uses

func (h Hash) String() string

type Info Uses

type Info struct {
    PieceLength int64  `bencode:"piece length"`      // BEP3
    Pieces      []byte `bencode:"pieces"`            // BEP3
    Name        string `bencode:"name"`              // BEP3
    Length      int64  `bencode:"length,omitempty"`  // BEP3, mutually exclusive with Files
    Private     *bool  `bencode:"private,omitempty"` // BEP27
    // TODO: Document this field.
    Source string     `bencode:"source,omitempty"`
    Files  []FileInfo `bencode:"files,omitempty"` // BEP3, mutually exclusive with Length
}

The info dictionary.

func (*Info) BuildFromFilePath Uses

func (info *Info) BuildFromFilePath(root string) (err error)

This is a helper that sets Files and Pieces from a root path and its children.

func (*Info) GeneratePieces Uses

func (info *Info) GeneratePieces(open func(fi FileInfo) (io.ReadCloser, error)) (err error)

Sets Pieces (the block of piece hashes in the Info) by using the passed function to get at the torrent data.

func (*Info) IsDir Uses

func (info *Info) IsDir() bool

func (*Info) NumPieces Uses

func (info *Info) NumPieces() int

func (*Info) Piece Uses

func (info *Info) Piece(index int) Piece

func (*Info) TotalLength Uses

func (info *Info) TotalLength() (ret int64)

func (*Info) UpvertedFiles Uses

func (info *Info) UpvertedFiles() []FileInfo

The files field, converted up from the old single-file in the parent info dict if necessary. This is a helper to avoid having to conditionally handle single and multi-file torrent infos.

type Magnet Uses

type Magnet struct {
    InfoHash    Hash       // Expected in this implementation
    Trackers    []string   // "tr" values
    DisplayName string     // "dn" value, if not empty
    Params      url.Values // All other values, such as "x.pe", "as", "xs" etc.
}

Magnet link components.

func ParseMagnetURI Uses

func ParseMagnetURI(uri string) (m Magnet, err error)

ParseMagnetURI parses Magnet-formatted URIs into a Magnet instance

func (Magnet) String Uses

func (m Magnet) String() string

type MetaInfo Uses

type MetaInfo struct {
    InfoBytes    bencode.Bytes `bencode:"info,omitempty"`          // BEP 3
    Announce     string        `bencode:"announce,omitempty"`      // BEP 3
    AnnounceList AnnounceList  `bencode:"announce-list,omitempty"` // BEP 12
    Nodes        []Node        `bencode:"nodes,omitempty"`         // BEP 5
    // Where's this specified? Mentioned at
    // https://wiki.theory.org/index.php/BitTorrentSpecification: (optional) the creation time of
    // the torrent, in standard UNIX epoch format (integer, seconds since 1-Jan-1970 00:00:00 UTC)
    CreationDate int64   `bencode:"creation date,omitempty,ignore_unmarshal_type_error"`
    Comment      string  `bencode:"comment,omitempty"`
    CreatedBy    string  `bencode:"created by,omitempty"`
    Encoding     string  `bencode:"encoding,omitempty"`
    UrlList      UrlList `bencode:"url-list,omitempty"` // BEP 19
}

func Load Uses

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

Load a MetaInfo from an io.Reader. Returns a non-nil error in case of failure.

func LoadFromFile Uses

func LoadFromFile(filename string) (*MetaInfo, error)

Convenience function for loading a MetaInfo from a file.

func (MetaInfo) HashInfoBytes Uses

func (mi MetaInfo) HashInfoBytes() (infoHash Hash)

func (*MetaInfo) Magnet Uses

func (mi *MetaInfo) Magnet(displayName string, infoHash Hash) (m Magnet)

Creates a Magnet from a MetaInfo.

func (*MetaInfo) SetDefaults Uses

func (mi *MetaInfo) SetDefaults()

Set good default values in preparation for creating a new MetaInfo file.

func (MetaInfo) UnmarshalInfo Uses

func (mi MetaInfo) UnmarshalInfo() (info Info, err error)

func (*MetaInfo) UpvertedAnnounceList Uses

func (mi *MetaInfo) UpvertedAnnounceList() AnnounceList

Returns the announce list converted from the old single announce field if necessary.

func (MetaInfo) Write Uses

func (mi MetaInfo) Write(w io.Writer) error

Encode to bencoded form.

type Node Uses

type Node string

func (*Node) UnmarshalBencode Uses

func (n *Node) UnmarshalBencode(b []byte) (err error)

type Piece Uses

type Piece struct {
    Info *Info
    // contains filtered or unexported fields
}

func (Piece) Hash Uses

func (p Piece) Hash() (ret Hash)

func (Piece) Index Uses

func (p Piece) Index() pieceIndex

func (Piece) Length Uses

func (p Piece) Length() int64

func (Piece) Offset Uses

func (p Piece) Offset() int64

type PieceKey Uses

type PieceKey struct {
    InfoHash Hash
    Index    pieceIndex
}

Uniquely identifies a piece.

type UrlList Uses

type UrlList []string

func (*UrlList) UnmarshalBencode Uses

func (me *UrlList) UnmarshalBencode(b []byte) error

Package metainfo imports 16 packages (graph) and is imported by 142 packages. Updated 2020-05-13. Refresh now. Tools for package owners.