package meta import ( "io/ioutil" "testing" "dim13.org/btget/bencode" ) var tors = map[string]string{ "bsd": "OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent", "ogg": "OpenBSD_songs_ogg-2016-03-25-0127.torrent", "deb": "debian-8.5.0-amd64-netinst.iso.torrent", "mul": "multi.torrent", } func Open(fname string) (Torrent, error) { var tor Torrent body, err := ioutil.ReadFile(fname) if err != nil { return Torrent{}, err } err = bencode.Unmarshal(body, &tor) if err != nil { return Torrent{}, err } return tor, nil } func TestPieces(t *testing.T) { tor, err := Open("../examples/" + tors["mul"]) if err != nil { t.Error(err) } for i := 0; i < tor.Info.NPieces(); i++ { n, off := tor.Info.FileOffset(i) t.Log(n, off) } } func TestPieces2(t *testing.T) { tor, err := Open("../examples/" + tors["mul"]) if err != nil { t.Error(err) } for i, p := range tor.Info.pieces() { t.Logf("%d %x\n", i, p) } }