]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Move TorrentSpec stuff into its own file
authorMatt Joiner <anacrolix@gmail.com>
Sun, 11 Sep 2016 04:09:40 +0000 (14:09 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 11 Sep 2016 04:09:40 +0000 (14:09 +1000)
client.go
spec.go [new file with mode: 0644]

index 98c9b12d770bbc288ef29c2c082c135d8c939525..4b0b1a25b101dbb063c69f458d6a913d7b906528 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1406,48 +1406,6 @@ type Handle interface {
        io.ReaderAt
 }
 
-// Specifies a new torrent for adding to a client. There are helpers for
-// magnet URIs and torrent metainfo files.
-type TorrentSpec struct {
-       // The tiered tracker URIs.
-       Trackers  [][]string
-       InfoHash  metainfo.Hash
-       InfoBytes []byte
-       // The name to use if the Name field from the Info isn't available.
-       DisplayName string
-       // The chunk size to use for outbound requests. Defaults to 16KiB if not
-       // set.
-       ChunkSize int
-       Storage   storage.ClientImpl
-}
-
-func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) {
-       m, err := metainfo.ParseMagnetURI(uri)
-       if err != nil {
-               return
-       }
-       spec = &TorrentSpec{
-               Trackers:    [][]string{m.Trackers},
-               DisplayName: m.DisplayName,
-               InfoHash:    m.InfoHash,
-       }
-       return
-}
-
-func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) (spec *TorrentSpec) {
-       info := mi.UnmarshalInfo()
-       spec = &TorrentSpec{
-               Trackers:    mi.AnnounceList,
-               InfoBytes:   mi.InfoBytes,
-               DisplayName: info.Name,
-               InfoHash:    mi.HashInfoBytes(),
-       }
-       if spec.Trackers == nil && mi.Announce != "" {
-               spec.Trackers = [][]string{{mi.Announce}}
-       }
-       return
-}
-
 func (cl *Client) AddTorrentInfoHash(infoHash metainfo.Hash) (t *Torrent, new bool) {
        cl.mu.Lock()
        defer cl.mu.Unlock()
diff --git a/spec.go b/spec.go
new file mode 100644 (file)
index 0000000..e6b58d8
--- /dev/null
+++ b/spec.go
@@ -0,0 +1,48 @@
+package torrent
+
+import (
+       "github.com/anacrolix/torrent/metainfo"
+       "github.com/anacrolix/torrent/storage"
+)
+
+// Specifies a new torrent for adding to a client. There are helpers for
+// magnet URIs and torrent metainfo files.
+type TorrentSpec struct {
+       // The tiered tracker URIs.
+       Trackers  [][]string
+       InfoHash  metainfo.Hash
+       InfoBytes []byte
+       // The name to use if the Name field from the Info isn't available.
+       DisplayName string
+       // The chunk size to use for outbound requests. Defaults to 16KiB if not
+       // set.
+       ChunkSize int
+       Storage   storage.ClientImpl
+}
+
+func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) {
+       m, err := metainfo.ParseMagnetURI(uri)
+       if err != nil {
+               return
+       }
+       spec = &TorrentSpec{
+               Trackers:    [][]string{m.Trackers},
+               DisplayName: m.DisplayName,
+               InfoHash:    m.InfoHash,
+       }
+       return
+}
+
+func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) (spec *TorrentSpec) {
+       info := mi.UnmarshalInfo()
+       spec = &TorrentSpec{
+               Trackers:    mi.AnnounceList,
+               InfoBytes:   mi.InfoBytes,
+               DisplayName: info.Name,
+               InfoHash:    mi.HashInfoBytes(),
+       }
+       if spec.Trackers == nil && mi.Announce != "" {
+               spec.Trackers = [][]string{{mi.Announce}}
+       }
+       return
+}