aboutsummaryrefslogtreecommitdiff
path: root/meta
diff options
context:
space:
mode:
Diffstat (limited to 'meta')
-rw-r--r--meta/torrent.go16
-rw-r--r--meta/torrent_test.go20
2 files changed, 17 insertions, 19 deletions
diff --git a/meta/torrent.go b/meta/torrent.go
index ecb0c02..12aa26e 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -4,7 +4,10 @@ package meta
import (
"fmt"
+ "io/ioutil"
"time"
+
+ "dim13.org/btget/bencode"
)
type Nodes map[string]int // Host:Port
@@ -31,3 +34,16 @@ func (t Torrent) String() string {
s += fmt.Sprintf("info hash: % x", t.InfoHash)
return s
}
+
+func Open(fname string) (Torrent, error) {
+ var tor Torrent
+ body, err := ioutil.ReadFile(fname)
+ if err != nil {
+ return Torrent{}, err
+ }
+ err = bencode.Unmarshal(body, &tor)
+ if err != nil {
+ return Torrent{}, err
+ }
+ return tor, nil
+}
diff --git a/meta/torrent_test.go b/meta/torrent_test.go
index 75cccc9..c7c4ded 100644
--- a/meta/torrent_test.go
+++ b/meta/torrent_test.go
@@ -1,11 +1,6 @@
package meta
-import (
- "io/ioutil"
- "testing"
-
- "dim13.org/btget/bencode"
-)
+import "testing"
var tors = map[string]string{
"bsd": "OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent",
@@ -14,19 +9,6 @@ var tors = map[string]string{
"mul": "multi.torrent",
}
-func Open(fname string) (Torrent, error) {
- var tor Torrent
- body, err := ioutil.ReadFile(fname)
- if err != nil {
- return Torrent{}, err
- }
- err = bencode.Unmarshal(body, &tor)
- if err != nil {
- return Torrent{}, err
- }
- return tor, nil
-}
-
func TestPieces(t *testing.T) {
tor, err := Open("../examples/" + tors["mul"])
if err != nil {