metainfo

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnnounceURL

type AnnounceURL string

type File

type File struct {
	Len  int      `bencode:"length"`
	Md5  []byte   `bencode:"md5sum" empty:"omit"`
	Path []string `bencode:"path"`
}

File contains information about a specific file in a .torrent file.

type FileParser

type FileParser struct {
	Filename string
}

FileParser parses a file with name Filename

func (*FileParser) Parse

func (fp *FileParser) Parse() (*MetaInfo, error)

type InfoDict

type InfoDict struct {
	Files    []File `bencode:"files" empty:"omit"`
	Len      int    `bencode:"length" empty:"omit"`
	Md5      []byte `bencode:"md5sum" empty:"omit"`
	Name     string `bencode:"name" empty:"omit"`
	PieceLen int    `bencode:"piece length"`
	Pieces   []byte `bencode:"pieces"`
	Private  int    `bencode:"private" empty:"omit"`
	//store info hash - we dont want to compute it every time
	Hash [20]byte `bencode:"-"`
}

InfoDict contains all the basic information about about the files that the .torrent file is mentioning.

func (*InfoDict) Bytes

func (info *InfoDict) Bytes(filename string) ([]byte, error)

Bytes returns the info dict in bencoded form. `filename` is a .torrent file

func (*InfoDict) FilesInfo

func (info *InfoDict) FilesInfo() []File

func (*InfoDict) NumPieces

func (info *InfoDict) NumPieces() int

func (*InfoDict) Parse

func (info *InfoDict) Parse() error

func (*InfoDict) PieceHash

func (info *InfoDict) PieceHash(i int) []byte

func (*InfoDict) PieceLength

func (info *InfoDict) PieceLength(i int) int

func (*InfoDict) PieceOffset

func (info *InfoDict) PieceOffset(i int) int64

func (*InfoDict) PiecesHash

func (info *InfoDict) PiecesHash() [][]byte

func (*InfoDict) TotalLength

func (info *InfoDict) TotalLength() (total int)

type InfoHashParser

type InfoHashParser struct {
	InfoHash [20]byte
}

func (*InfoHashParser) Parse

func (ip *InfoHashParser) Parse() (*MetaInfo, error)

type MagnetParser

type MagnetParser struct {
	URI string
}

MagnetParser parses an URI

func (*MagnetParser) Parse

func (mp *MagnetParser) Parse() (*MetaInfo, error)

type MetaInfo

type MetaInfo struct {
	Announce     string     `bencode:"announce"`
	AnnounceList [][]string `bencode:"announce-list" empty:"omit"`
	Comment      string     `bencode:"comment" empty:"omit"`
	Created      string     `bencode:"created by" empty:"omit"`
	CreationDate int        `bencode:"creation date" empty:"omit"`
	Encoding     string     `bencode:"encoding" empty:"omit"`
	Info         *InfoDict  `bencode:"info"`
	InfoBytes    []byte     `bencode:"-"`
}

func LoadMetainfoFile

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

func (*MetaInfo) CreateTorrentFile

func (m *MetaInfo) CreateTorrentFile(fileName string) error

func (*MetaInfo) Parse

func (m *MetaInfo) Parse() error

Parse makes some checks based on a torrent file. Maybe further checks should be made beyond these.

type Parser

type Parser interface {
	Parse() (*MetaInfo, error)
}

Parser parses an input source (e.g file,uri) into a MetaInfo struct

type ReaderParser

type ReaderParser struct {
	R io.Reader
}

func (*ReaderParser) Parse

func (rp *ReaderParser) Parse() (*MetaInfo, error)

Parse reads until EOF from R and then parses the read bytes

Jump to

Keyboard shortcuts

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