metainfo

package
v0.0.0-...-57e5bf5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2016 License: MPL-2.0 Imports: 16 Imported by: 0

README

A library for manipulating ".torrent" files.

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"`
}

Information specific to a single file inside the MetaInfo structure.

type Hash

type Hash [20]byte

20-byte SHA1 hash used for info and pieces.

func HashBytes

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

func (*Hash) AsString

func (h *Hash) AsString() string

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (*Hash) FromHexString

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

func (Hash) HexString

func (h Hash) HexString() string

type Info

type Info struct {
	PieceLength int64      `bencode:"piece length"`
	Pieces      []byte     `bencode:"pieces"`
	Name        string     `bencode:"name"`
	Length      int64      `bencode:"length,omitempty"`
	Private     *bool      `bencode:"private,omitempty"`
	Files       []FileInfo `bencode:"files,omitempty"`
}

The info dictionary.

func (*Info) BuildFromFilePath

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

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

Set info.Pieces by hashing info.Files.

func (*Info) IsDir

func (info *Info) IsDir() bool

func (*Info) NumPieces

func (info *Info) NumPieces() int

func (*Info) TotalLength

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

func (*Info) UpvertedFiles

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 InfoEx

type InfoEx struct {
	Info
	// Set when unmarshalling, and used when marshalling. Call .UpdateBytes to
	// set it by bencoding Info.
	Bytes []byte
}

A wrapper around Info that exposes the Bytes directly, in case marshalling and unmarshalling Info doesn't produce the same bytes.

func (*InfoEx) Hash

func (ie *InfoEx) Hash() Hash

Returns the SHA1 hash of .Bytes.

func (*InfoEx) MarshalBencode

func (ie *InfoEx) MarshalBencode() ([]byte, error)

func (*InfoEx) Piece

func (info *InfoEx) Piece(i int) Piece

func (*InfoEx) UnmarshalBencode

func (ie *InfoEx) UnmarshalBencode(data []byte) error

func (*InfoEx) UpdateBytes

func (ie *InfoEx) UpdateBytes()

Marshals .Info, and sets .Bytes with the result.

type Magnet

type Magnet struct {
	InfoHash    Hash
	Trackers    []string
	DisplayName string
}

Magnet link components.

func ParseMagnetURI

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

ParseMagnetURI parses Magnet-formatted URIs into a Magnet instance

func (Magnet) String

func (m Magnet) String() string

type MetaInfo

type MetaInfo struct {
	Info         InfoEx      `bencode:"info"`
	Announce     string      `bencode:"announce,omitempty"`
	AnnounceList [][]string  `bencode:"announce-list,omitempty"`
	Nodes        []Node      `bencode:"nodes,omitempty"`
	CreationDate int64       `bencode:"creation date,omitempty"`
	Comment      string      `bencode:"comment,omitempty"`
	CreatedBy    string      `bencode:"created by,omitempty"`
	Encoding     string      `bencode:"encoding,omitempty"`
	URLList      interface{} `bencode:"url-list,omitempty"`
}

func Load

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

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

Convenience function for loading a MetaInfo from a file.

func (*MetaInfo) Magnet

func (mi *MetaInfo) Magnet() (m Magnet)

Creates a Magnet from a MetaInfo.

func (*MetaInfo) SetDefaults

func (mi *MetaInfo) SetDefaults()

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

func (*MetaInfo) Write

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

Encode to bencoded form.

type Node

type Node string

func (*Node) UnmarshalBencode

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

type Piece

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

func (Piece) Hash

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

func (Piece) Length

func (p Piece) Length() int64

func (Piece) Offset

func (p Piece) Offset() int64

Jump to

Keyboard shortcuts

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