summaryrefslogtreecommitdiff
path: root/src/Data/Torrent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r--src/Data/Torrent.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 3d5f669e..464bc5bb 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -52,6 +52,7 @@ import qualified Data.ByteString.Lazy as Lazy
52import qualified Data.List as L 52import qualified Data.List as L
53import Data.Text (Text) 53import Data.Text (Text)
54import Data.Serialize as S hiding (Result) 54import Data.Serialize as S hiding (Result)
55import Text.PrettyPrint
55import qualified Crypto.Hash.SHA1 as C 56import qualified Crypto.Hash.SHA1 as C
56import Network.URI 57import Network.URI
57import System.FilePath 58import System.FilePath
@@ -307,9 +308,10 @@ newtype InfoHash = InfoHash { getInfoHash :: ByteString }
307 308
308instance BEncodable InfoHash where 309instance BEncodable InfoHash where
309 toBEncode = toBEncode . getInfoHash 310 toBEncode = toBEncode . getInfoHash
311 fromBEncode be = InfoHash <$> fromBEncode be
310 312
311instance Show InfoHash where 313instance Show InfoHash where
312 show = BC.unpack . ppInfoHash 314 show = render . ppInfoHash
313 315
314instance Serialize InfoHash where 316instance Serialize InfoHash where
315 put = putByteString . getInfoHash 317 put = putByteString . getInfoHash
@@ -329,9 +331,11 @@ hash = InfoHash . C.hash
329hashlazy :: Lazy.ByteString -> InfoHash 331hashlazy :: Lazy.ByteString -> InfoHash
330hashlazy = InfoHash . C.hashlazy 332hashlazy = InfoHash . C.hashlazy
331 333
332ppInfoHash :: InfoHash -> ByteString 334ppInfoHash :: InfoHash -> Doc
333ppInfoHash = Lazy.toStrict . B.toLazyByteString . 335ppInfoHash = text . BC.unpack . Lazy.toStrict . ppHex . getInfoHash
334 foldMap (B.primFixed B.word8HexFixed) . B.unpack . getInfoHash 336
337ppHex :: ByteString -> Lazy.ByteString
338ppHex = B.toLazyByteString . foldMap (B.primFixed B.word8HexFixed) . B.unpack
335 339
336addHashToURI :: URI -> InfoHash -> URI 340addHashToURI :: URI -> InfoHash -> URI
337addHashToURI uri s = uri { 341addHashToURI uri s = uri {