//----------------------------------------------------------------------------
+// SingleFile represents the specific data of the single file torrent file. That
+// includes length of the file and its recommended name.
type SingleFile struct {
Name string
Length int64
//----------------------------------------------------------------------------
+// MultiFile represents the specific data of the multiple files torrent
+// file. That includes Name of the directory which will contain all the files
+// and the files information.
type MultiFile struct {
Name string
Files []FileInfo
}
+// Information of a single file in multiple files torrent file.
type FileInfo struct {
Length int64
Path []string
//----------------------------------------------------------------------------
+// File is the type you should use when reading torrent files. See Load and
+// LoadFromFile functions. All the fields are intended to be read-only. The
+// "Info" field has SingleFile or MultiFile type, use the type switch or type
+// assertion to determine the exact type.
type File struct {
- // the type is SingleFile or MultiFile
Info interface{}
InfoHash []byte
PieceLength int64
URLList []string
}
+// Load a File from an io.Reader. Returns a non-nil error in case of failure.
func Load(r io.Reader) (*File, error) {
var file File
var data torrent_data
return &file, nil
}
+// Convenience function for loading a torrent.File from a file.
func LoadFromFile(filename string) (*File, error) {
f, err := os.Open(filename)
if err != nil {