diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-05-19 02:34:39 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-05-19 02:34:39 +0400 |
commit | e3da90564140f7140cfa3128d4b340e696fd5b47 (patch) | |
tree | da78e4646b192f61de9a9ab498e78f3658d7e11a /src/Data/Torrent.hs | |
parent | 1f87b0c2b67bfc7ee05e3076dcc10c96aed76aa7 (diff) |
~ Prettify Torrent module a bit.
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r-- | src/Data/Torrent.hs | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index 5678d7eb..873d90dd 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -8,6 +8,7 @@ | |||
8 | -- This module provides torrent metainfo serialization. | 8 | -- This module provides torrent metainfo serialization. |
9 | {-# OPTIONS -fno-warn-orphans #-} | 9 | {-# OPTIONS -fno-warn-orphans #-} |
10 | {-# LANGUAGE OverloadedStrings #-} | 10 | {-# LANGUAGE OverloadedStrings #-} |
11 | {-# LANGUAGE RecordWildCards #-} | ||
11 | module Data.Torrent | 12 | module Data.Torrent |
12 | ( module Data.Torrent.InfoHash | 13 | ( module Data.Torrent.InfoHash |
13 | , Torrent(..), ContentInfo(..), FileInfo(..) | 14 | , Torrent(..), ContentInfo(..), FileInfo(..) |
@@ -142,17 +143,17 @@ instance BEncodable URI where | |||
142 | {-# INLINE fromBEncode #-} | 143 | {-# INLINE fromBEncode #-} |
143 | 144 | ||
144 | instance BEncodable Torrent where | 145 | instance BEncodable Torrent where |
145 | toBEncode t = fromAscAssocs | 146 | toBEncode Torrent {..} = fromAscAssocs |
146 | [ "announce" --> tAnnounce t | 147 | [ "announce" --> tAnnounce |
147 | , "announce-list" -->? tAnnounceList t | 148 | , "announce-list" -->? tAnnounceList |
148 | , "comment" -->? tComment t | 149 | , "comment" -->? tComment |
149 | , "created by" -->? tCreatedBy t | 150 | , "created by" -->? tCreatedBy |
150 | , "creation date" -->? tCreationDate t | 151 | , "creation date" -->? tCreationDate |
151 | , "encoding" -->? tEncoding t | 152 | , "encoding" -->? tEncoding |
152 | , "info" --> tInfo t | 153 | , "info" --> tInfo |
153 | , "publisher" -->? tPublisher t | 154 | , "publisher" -->? tPublisher |
154 | , "publisher-url" -->? tPublisherURL t | 155 | , "publisher-url" -->? tPublisherURL |
155 | , "signature" -->? tSignature t | 156 | , "signature" -->? tSignature |
156 | ] | 157 | ] |
157 | 158 | ||
158 | fromBEncode (BDict d) | Just info <- M.lookup "info" d = | 159 | fromBEncode (BDict d) | Just info <- M.lookup "info" d = |
@@ -172,23 +173,23 @@ instance BEncodable Torrent where | |||
172 | 173 | ||
173 | 174 | ||
174 | instance BEncodable ContentInfo where | 175 | instance BEncodable ContentInfo where |
175 | toBEncode ti@(SingleFile { }) = fromAscAssocs | 176 | toBEncode SingleFile {..} = fromAscAssocs |
176 | [ "length" --> ciLength ti | 177 | [ "length" --> ciLength |
177 | , "md5sum" -->? ciMD5sum ti | 178 | , "md5sum" -->? ciMD5sum |
178 | , "name" --> ciName ti | 179 | , "name" --> ciName |
179 | 180 | ||
180 | , "piece length" --> ciPieceLength ti | 181 | , "piece length" --> ciPieceLength |
181 | , "pieces" --> ciPieces ti | 182 | , "pieces" --> ciPieces |
182 | , "private" -->? ciPrivate ti | 183 | , "private" -->? ciPrivate |
183 | ] | 184 | ] |
184 | 185 | ||
185 | toBEncode ti@(MultiFile {}) = fromAscAssocs | 186 | toBEncode MultiFile {..} = fromAscAssocs |
186 | [ "files" --> ciFiles ti | 187 | [ "files" --> ciFiles |
187 | , "name" --> ciName ti | 188 | , "name" --> ciName |
188 | 189 | ||
189 | , "piece length" --> ciPieceLength ti | 190 | , "piece length" --> ciPieceLength |
190 | , "pieces" --> ciPieces ti | 191 | , "pieces" --> ciPieces |
191 | , "private" -->? ciPrivate ti | 192 | , "private" -->? ciPrivate |
192 | ] | 193 | ] |
193 | 194 | ||
194 | fromBEncode (BDict d) | 195 | fromBEncode (BDict d) |
@@ -209,10 +210,10 @@ instance BEncodable ContentInfo where | |||
209 | 210 | ||
210 | 211 | ||
211 | instance BEncodable FileInfo where | 212 | instance BEncodable FileInfo where |
212 | toBEncode tf = fromAssocs | 213 | toBEncode FileInfo {..} = fromAssocs |
213 | [ "length" --> fiLength tf | 214 | [ "length" --> fiLength |
214 | , "md5sum" -->? fiMD5sum tf | 215 | , "md5sum" -->? fiMD5sum |
215 | , "path" --> fiPath tf | 216 | , "path" --> fiPath |
216 | ] | 217 | ] |
217 | 218 | ||
218 | fromBEncode (BDict d) = | 219 | fromBEncode (BDict d) = |