1
0
mirror of https://github.com/veggiedefender/torrent-client.git synced 2025-11-06 09:29:16 +02:00

Return plain struct from toTorrentFile

This commit is contained in:
Jesse Li
2020-01-02 10:27:00 -05:00
parent 7e8b3413ac
commit 4fd40f9f0a
2 changed files with 11 additions and 11 deletions

View File

@@ -65,11 +65,11 @@ func (t *TorrentFile) Download() ([]byte, error) {
}
// Open parses a torrent file
func Open(r io.Reader) (*TorrentFile, error) {
func Open(r io.Reader) (TorrentFile, error) {
bto := bencodeTorrent{}
err := bencode.Unmarshal(r, &bto)
if err != nil {
return nil, err
return TorrentFile{}, err
}
return bto.toTorrentFile()
}
@@ -100,14 +100,14 @@ func (i *bencodeInfo) splitPieceHashes() ([][20]byte, error) {
return hashes, nil
}
func (bto *bencodeTorrent) toTorrentFile() (*TorrentFile, error) {
func (bto *bencodeTorrent) toTorrentFile() (TorrentFile, error) {
infoHash, err := bto.Info.hash()
if err != nil {
return nil, err
return TorrentFile{}, err
}
pieceHashes, err := bto.Info.splitPieceHashes()
if err != nil {
return nil, err
return TorrentFile{}, err
}
t := TorrentFile{
Announce: bto.Announce,
@@ -117,5 +117,5 @@ func (bto *bencodeTorrent) toTorrentFile() (*TorrentFile, error) {
Length: bto.Info.Length,
Name: bto.Info.Name,
}
return &t, nil
return t, nil
}