metainfo

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

* package for parsing bitorrent meta info objects

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	// length of file
	Length uint64 `bencode:"length"`
	// relative path of file
	Path FilePath `bencode:"path"`
	// md5sum
	Sum []byte `bencode:"md5sum,omitempty"`
}

type FilePath

type FilePath []string

func (FilePath) FilePath

func (f FilePath) FilePath(base string) string

get filepath

type Info

type Info struct {
	// length of pices in bytes
	PieceLength uint32 `bencode:"piece length"`
	// piece data
	Pieces []byte `bencode:"pieces"`
	// name of root file
	Path string `bencode:"name"`
	// file metadata
	Files []FileInfo `bencode:"files,omitempty"`
	// private torrent
	Private *uint64 `bencode:"private,omitempty"`
	// length of file in signle file mode
	Length uint64 `bencode:"length,omitempty"`
	// md5sum
	Sum []byte `bencode:"md5sum,omitempty"`
}

info section of torrent file

func (Info) CheckPiece

func (i Info) CheckPiece(p *common.PieceData) bool

check if a piece is valid against the pieces in this info section

func (Info) GetFiles

func (i Info) GetFiles() (infos []FileInfo)

get fileinfos from this info section

func (Info) NumPieces

func (i Info) NumPieces() uint32

type TorrentFile

type TorrentFile struct {
	Info         Info               `bencode:"-"`
	RawInfo      bencode.RawMessage `bencode:"info"`
	Announce     string             `bencode:"announce"`
	AnnounceList [][]string         `bencode:"announce-list"`
	Created      int64              `bencode:"created"`
	Comment      []byte             `bencode:"comment"`
	CreatedBy    []byte             `bencode:"created by"`
	Encoding     []byte             `bencode:"encoding"`
}

a torrent file

func TorrentFileFromInfo added in v0.4.6

func TorrentFileFromInfo(info Info) (tf *TorrentFile, err error)

func TorrentFileFromInfoBytes added in v0.4.6

func TorrentFileFromInfoBytes(bytes []byte) (tf *TorrentFile, err error)

func (*TorrentFile) BDecode

func (tf *TorrentFile) BDecode(r io.Reader) (err error)

load from an io.Reader

func (*TorrentFile) BEncode

func (tf *TorrentFile) BEncode(w io.Writer) (err error)

bencode this file via an io.Writer

func (*TorrentFile) GetAllAnnounceURLS

func (tf *TorrentFile) GetAllAnnounceURLS() (l []string)

func (*TorrentFile) Infohash

func (tf *TorrentFile) Infohash() (ih common.Infohash)

calculate infohash

func (*TorrentFile) IsPrivate

func (tf *TorrentFile) IsPrivate() bool

IsPrivate returns true if this torrent is a private torrent

func (*TorrentFile) IsSingleFile

func (tf *TorrentFile) IsSingleFile() bool

return true if this torrent is for a single file

func (*TorrentFile) LengthOfPiece

func (tf *TorrentFile) LengthOfPiece(idx uint32) (l uint32)

func (*TorrentFile) TorrentName

func (tf *TorrentFile) TorrentName() string

func (*TorrentFile) TotalSize

func (tf *TorrentFile) TotalSize() uint64

get total size of files from torrent info section

Jump to

Keyboard shortcuts

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