2
0
mirror of synced 2025-02-24 14:48:27 +00:00

Add UpvertedFiles() to Info to make single-file torrents usable like

multi-file torrents.
This commit is contained in:
Matt Joiner 2015-01-28 01:26:18 +11:00
parent 916c9c822a
commit 5a3a110e99

View File

@ -46,6 +46,19 @@ type Info struct {
Files []FileInfo `bencode:"files,omitempty"`
}
// The files field, converted up from the old single-file in the parent info
// dict if necessary. This is a helper to avoid having to conditionally handle
// single and multi-file torrent infos.
func (i *Info) UpvertedFiles() []FileInfo {
if len(i.Files) == 0 {
return []FileInfo{{
Length: i.Length,
Path: []string{i.Name},
}}
}
return i.Files
}
// The info dictionary with its hash and raw bytes exposed, as these are
// important to Bittorrent.
type InfoEx struct {