internal/testutil.Info: Support multi-file Torrents

This commit is contained in:
Matt Joiner 2022-06-14 10:06:36 +10:00
parent 65896d4cec
commit caf35cd9b8
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
1 changed files with 7 additions and 0 deletions

View File

@ -44,6 +44,13 @@ func (t *Torrent) Info(pieceLength int64) metainfo.Info {
}
if t.IsDir() {
info.Length = int64(len(t.Files[0].Data))
} else {
for _, f := range t.Files {
info.Files = append(info.Files, metainfo.FileInfo{
Path: []string{f.Name},
Length: int64(len(f.Data)),
})
}
}
err := info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil