]> Sergey Matveev's repositories - btrtrc.git/blobdiff - metainfo/metainfo.go
Drop support for go 1.20
[btrtrc.git] / metainfo / metainfo.go
index cd787260c150e972b8987713b65904a7f30c766b..93f9103b968b09f661cb3aa9a9a6618a8102cdb6 100644 (file)
@@ -1,6 +1,7 @@
 package metainfo
 
 import (
+       "bufio"
        "io"
        "net/url"
        "os"
@@ -10,10 +11,10 @@ import (
 )
 
 type MetaInfo struct {
-       InfoBytes    bencode.Bytes `bencode:"info,omitempty"`          // BEP 3
-       Announce     string        `bencode:"announce,omitempty"`      // BEP 3
-       AnnounceList AnnounceList  `bencode:"announce-list,omitempty"` // BEP 12
-       Nodes        []Node        `bencode:"nodes,omitempty"`         // BEP 5
+       InfoBytes    bencode.Bytes `bencode:"info,omitempty"`                              // BEP 3
+       Announce     string        `bencode:"announce,omitempty"`                          // BEP 3
+       AnnounceList AnnounceList  `bencode:"announce-list,omitempty"`                     // BEP 12
+       Nodes        []Node        `bencode:"nodes,omitempty,ignore_unmarshal_type_error"` // BEP 5
        // Where's this specified? Mentioned at
        // https://wiki.theory.org/index.php/BitTorrentSpecification: (optional) the creation time of
        // the torrent, in standard UNIX epoch format (integer, seconds since 1-Jan-1970 00:00:00 UTC)
@@ -43,7 +44,9 @@ func LoadFromFile(filename string) (*MetaInfo, error) {
                return nil, err
        }
        defer f.Close()
-       return Load(f)
+       var buf bufio.Reader
+       buf.Reset(f)
+       return Load(&buf)
 }
 
 func (mi MetaInfo) UnmarshalInfo() (info Info, err error) {