...

Package parser

import "github.com/concurrency-8/parser"
Overview
Index

Overview ▾

Variables

BLOCK_LEN is length of block

var BLOCK_LEN = uint32(math.Pow(2, 14))

func BlockLen

func BlockLen(torrent TorrentFile, pieceIndex uint32, blockIndex uint32) (length uint32, err error)

BlockLen calculates length of ith block in jth piece

func BlocksPerPiece

func BlocksPerPiece(torrent TorrentFile, index uint32) (blocks uint32, err error)

BlocksPerPiece returns number of blocks in a ith piece

func GetTorrentFileList

func GetTorrentFileList() []string

GetTorrentFileList gives the list of torrentfiles (these should be alive, in test_torrents)

func PieceLen

func PieceLen(torrent TorrentFile, index uint32) (length uint32, err error)

PieceLen returns the length of ith piece of file

type File

File contains length and path of a File in the torrent.

type File struct {
    Path        []string
    Length      uint64
    FilePointer *os.File
}

type FileMetaData

FileMetaData contains MetaData about a File.

type FileMetaData struct {
    Path   []string `bencode:"path"`
    Length uint64   `bencode:"length"`
}

type InfoMetaData

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

type MetaData

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

type Piece

Piece Holds a piece

type Piece struct {
    Blocks []PieceBlock
}

type 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

func RandomPieceBlock(torrent TorrentFile) PieceBlock

RandomPieceBlock returns a random PieceBlock object from torrent

type TorrentFile

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

func Parse(reader io.Reader) (TorrentFile, error)

Parse parses from a stream and returns a pointer to a TorrentFile.

func ParseFromFile

func ParseFromFile(path string) (TorrentFile, error)

ParseFromFile parses a .torrent file.