BLOCK_LEN is length of block
var BLOCK_LEN = uint32(math.Pow(2, 14))
func BlockLen(torrent TorrentFile, pieceIndex uint32, blockIndex uint32) (length uint32, err error)
BlockLen calculates length of ith block in jth piece
func BlocksPerPiece(torrent TorrentFile, index uint32) (blocks uint32, err error)
BlocksPerPiece returns number of blocks in a ith piece
func GetTorrentFileList() []string
GetTorrentFileList gives the list of torrentfiles (these should be alive, in test_torrents)
func PieceLen(torrent TorrentFile, index uint32) (length uint32, err error)
PieceLen returns the length of ith piece of file
File contains length and path of a File in the torrent.
type File struct {
Path []string
Length uint64
FilePointer *os.File
}
FileMetaData contains MetaData about a File.
type FileMetaData struct {
Path []string `bencode:"path"`
Length uint64 `bencode:"length"`
}
InfoMetaData contains MetaData about the torrent.
type InfoMetaData struct {
PieceLength uint32 `bencode:"piece length"`
Piece []byte `bencode:"pieces"`
Name string `bencode:"name"`
Length uint64 `bencode:"length"`
Files bencode.RawMessage `bencode:"files"`
}
MetaData contains MetaData about the file.
type MetaData struct {
Announce string `bencode:"announce"`
AnnounceList [][]string `bencode:"announce-list"`
Comment string `bencode:"comment"`
CreatedBy string `bencode:"created by"`
CreatedAt int64 `bencode:"creation date"`
Info bencode.RawMessage `bencode:"info"`
}
Piece Holds a piece
type Piece struct {
Blocks []PieceBlock
}
PieceBlock is struct for a block of a piece
type PieceBlock struct {
Index uint32
Begin uint32
Length uint32
Nblocks uint32
Bytes []byte
}
func RandomPieceBlock(torrent TorrentFile) PieceBlock
RandomPieceBlock returns a random PieceBlock object from torrent
TorrentFile contains information about the torrent.
type TorrentFile struct {
Name string
Announce []string
Comment string
CreatedBy string
CreatedAt time.Time
InfoHash string
Length uint64
Files []*File
PieceLength uint32
Piece []byte
}
func Parse(reader io.Reader) (TorrentFile, error)
Parse parses from a stream and returns a pointer to a TorrentFile.
func ParseFromFile(path string) (TorrentFile, error)
ParseFromFile parses a .torrent file.