8 "github.com/anacrolix/missinggo/assert"
10 "github.com/anacrolix/torrent/bencode"
11 "github.com/anacrolix/torrent/metainfo"
24 func (t *Torrent) IsDir() bool {
25 return len(t.Files) == 1 && t.Files[0].Name == ""
28 func (t *Torrent) GetFile(name string) *File {
29 if t.IsDir() && t.Name == name {
32 for _, f := range t.Files {
40 func (t *Torrent) Info(pieceLength int64) metainfo.Info {
41 info := metainfo.Info{
43 PieceLength: pieceLength,
46 info.Length = int64(len(t.Files[0].Data))
48 err := info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
49 return ioutil.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil
55 func (t *Torrent) Metainfo(pieceLength int64) *metainfo.MetaInfo {
56 mi := metainfo.MetaInfo{}
58 mi.InfoBytes, err = bencode.Marshal(t.Info(pieceLength))