8 "github.com/anacrolix/missinggo/expect"
9 "github.com/anacrolix/torrent/bencode"
10 "github.com/anacrolix/torrent/metainfo"
23 func (t *Torrent) IsDir() bool {
24 return len(t.Files) == 1 && t.Files[0].Name == ""
27 func (t *Torrent) GetFile(name string) *File {
28 if t.IsDir() && t.Name == name {
31 for _, f := range t.Files {
39 func (t *Torrent) Info(pieceLength int64) metainfo.Info {
40 info := metainfo.Info{
42 PieceLength: pieceLength,
45 info.Length = int64(len(t.Files[0].Data))
47 err := info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
48 return ioutil.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil
54 func (t *Torrent) Metainfo(pieceLength int64) *metainfo.MetaInfo {
55 mi := metainfo.MetaInfo{}
57 mi.InfoBytes, err = bencode.Marshal(t.Info(pieceLength))