func NewTorrent(filename string, quit chan struct{}) (*Torrent, error) {
	torrent := &Torrent{quit: quit}
	file, err := os.Open(filename)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()
	m, err := bencode.Decode(file)
	if err != nil {
		return torrent, err
	}
	metaMap, ok := m.(map[string]interface{})
	if !ok {
		err = errors.New("Couldn't parse torrent file")
		return torrent, err
	}
	infoDict, ok := metaMap["info"]
	if !ok {
		err = errors.New("Unable to locate info dict in torrent file")
		return torrent, err
	}
	var b bytes.Buffer
	err = bencode.Marshal(&b, infoDict)
	if err != nil {
		return torrent, err
	}
	h := sha1.New()
	h.Write(b.Bytes())
	torrent.infoHash = append(torrent.infoHash, h.Sum(nil)...)
	file.Seek(0, 0)
	err = bencode.Unmarshal(file, &torrent.metaInfo)
	if err != nil {
		return torrent, err
	}
	log.Printf("Parse : ParseTorrentFile : Successfully parsed %s", filename)
	log.Printf("Parse : ParseTorrentFile : The length of each piece is %d", torrent.metaInfo.Info.PieceLength)
	return torrent, nil
}
NewTorrent opens the torrent filename specified and parses it,
returning a Torrent structure with the MetaInfo and SHA-1 hash of the
Info dictionary.
package main
import (
	"bytes"
	"crypto/sha1"
	"errors"
	"github.com/jackpal/bencode-go"
	"log"
	"os"
	"time"
)
type Torrent struct {
	metaInfo MetaInfo
	infoHash []byte
	peer     chan PeerTuple
	quit     chan struct{}
}
type MetaInfo struct {
	Info struct {
		PieceLength int `bencode:"piece length"`
		Pieces      string
		Private     int
		Name        string
		Length      int
		Md5sum      string
		Files       []struct {
			Length int
			Md5sum string
			Path   []string
		}
	}
	Announce     string
	AnnounceList [][]string `bencode:"announce-list"`
	CreationDate int        `bencode:"creation date"`
	Comment      string
	CreatedBy    string `bencode:"created by"`
	Encoding     string
}