summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Torrent.hs24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 83f4094c..3aad2827 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -32,7 +32,7 @@ data Torrent = Torrent {
32 , tAnnounceList :: Maybe [[URI]] 32 , tAnnounceList :: Maybe [[URI]]
33 -- ^ Announce list add multiple tracker support. 33 -- ^ Announce list add multiple tracker support.
34 -- 34 --
35 -- BEP 12: http://www.bittorrent.org/beps/bep_0012.html 35 -- BEP 12: <http://www.bittorrent.org/beps/bep_0012.html>
36 36
37 , tComment :: Maybe Text 37 , tComment :: Maybe Text
38 -- ^ Free-form comments of the author. 38 -- ^ Free-form comments of the author.
@@ -47,9 +47,8 @@ data Torrent = Torrent {
47 -- ^ String encoding format used to generate the pieces part of 47 -- ^ String encoding format used to generate the pieces part of
48 -- the info dictionary in the .torrent metafile. 48 -- the info dictionary in the .torrent metafile.
49 49
50 -- ^ Info about each content file.
51 , tInfo :: TorrentInfo 50 , tInfo :: TorrentInfo
52 51 -- ^ Info about each content file.
53 52
54 , tPublisher :: Maybe URI 53 , tPublisher :: Maybe URI
55 -- ^ Containing the RSA public key of the publisher of the torrent. 54 -- ^ Containing the RSA public key of the publisher of the torrent.
@@ -69,7 +68,7 @@ data TorrentInfo =
69 -- ^ Length of the file in bytes. 68 -- ^ Length of the file in bytes.
70 69
71 , tMD5sum :: Maybe ByteString 70 , tMD5sum :: Maybe ByteString
72 -- | 32 character long MD5 sum of the file. 71 -- ^ 32 character long MD5 sum of the file.
73 -- Used by third-party tools, not by bittorrent protocol itself. 72 -- Used by third-party tools, not by bittorrent protocol itself.
74 73
75 , tName :: ByteString 74 , tName :: ByteString
@@ -87,7 +86,7 @@ data TorrentInfo =
87 -- ^ If set the client MUST publish its presence to get other peers ONLY 86 -- ^ If set the client MUST publish its presence to get other peers ONLY
88 -- via the trackers explicity described in the metainfo file. 87 -- via the trackers explicity described in the metainfo file.
89 -- 88 --
90 -- BEP 27: http://www.bittorrent.org/beps/bep_0027.html 89 -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html>
91 } 90 }
92 91
93 | MultiFile { 92 | MultiFile {
@@ -97,19 +96,9 @@ data TorrentInfo =
97 , tName :: ByteString 96 , tName :: ByteString
98 -- | The file path of the directory in which to store all the files. 97 -- | The file path of the directory in which to store all the files.
99 98
100
101
102 , tPieceLength :: Int 99 , tPieceLength :: Int
103
104 -- ^ Number of bytes in each piece.
105 , tPieces :: ByteString 100 , tPieces :: ByteString
106 -- ^ Concatenation of all 20-byte SHA1 hash values.
107
108 , tPrivate :: Maybe Bool 101 , tPrivate :: Maybe Bool
109 -- ^ If set the client MUST publish its presence to get other peers ONLY
110 -- via the trackers explicity described in the metainfo file,
111 --
112 -- BEP 27: http://www.bittorrent.org/beps/bep_0027.html
113 } deriving (Show, Read, Eq) 102 } deriving (Show, Read, Eq)
114 103
115-- | Contain info about one single file. 104-- | Contain info about one single file.
@@ -118,7 +107,7 @@ data TorrentFile = TorrentFile {
118 -- ^ Length of the file in bytes. 107 -- ^ Length of the file in bytes.
119 108
120 , tfMD5sum :: Maybe ByteString 109 , tfMD5sum :: Maybe ByteString
121 -- | 32 character long MD5 sum of the file. 110 -- ^ 32 character long MD5 sum of the file.
122 -- Used by third-party tools, not by bittorrent protocol itself. 111 -- Used by third-party tools, not by bittorrent protocol itself.
123 112
124 , tfPath :: [ByteString] 113 , tfPath :: [ByteString]
@@ -219,5 +208,6 @@ instance BEncodable TorrentFile where
219 fromBEncode _ = decodingError "TorrentFile" 208 fromBEncode _ = decodingError "TorrentFile"
220 209
221 210
211-- | Read and decode a .torrent file.
222fromFile :: FilePath -> IO (Result Torrent) 212fromFile :: FilePath -> IO (Result Torrent)
223fromFile filepath = (fromBEncode <=< decode) <$> B.readFile filepath 213fromFile filepath = decoded <$> B.readFile filepath