diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-02 06:43:00 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-02 06:43:00 +0400 |
commit | 4de96724e4006589022e08b6ed247784f958b508 (patch) | |
tree | 7c7807a4e9425fca1151e1fed909a3643238278f /src/Data/Torrent.hs | |
parent | dea6c9b2ea1037ee54f1908ebc6a5e193e0cfac6 (diff) |
~ Use pretty package for pretty print.
This is a bit faster and pretty!
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r-- | src/Data/Torrent.hs | 12 |
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 | |||
52 | import qualified Data.List as L | 52 | import qualified Data.List as L |
53 | import Data.Text (Text) | 53 | import Data.Text (Text) |
54 | import Data.Serialize as S hiding (Result) | 54 | import Data.Serialize as S hiding (Result) |
55 | import Text.PrettyPrint | ||
55 | import qualified Crypto.Hash.SHA1 as C | 56 | import qualified Crypto.Hash.SHA1 as C |
56 | import Network.URI | 57 | import Network.URI |
57 | import System.FilePath | 58 | import System.FilePath |
@@ -307,9 +308,10 @@ newtype InfoHash = InfoHash { getInfoHash :: ByteString } | |||
307 | 308 | ||
308 | instance BEncodable InfoHash where | 309 | instance BEncodable InfoHash where |
309 | toBEncode = toBEncode . getInfoHash | 310 | toBEncode = toBEncode . getInfoHash |
311 | fromBEncode be = InfoHash <$> fromBEncode be | ||
310 | 312 | ||
311 | instance Show InfoHash where | 313 | instance Show InfoHash where |
312 | show = BC.unpack . ppInfoHash | 314 | show = render . ppInfoHash |
313 | 315 | ||
314 | instance Serialize InfoHash where | 316 | instance Serialize InfoHash where |
315 | put = putByteString . getInfoHash | 317 | put = putByteString . getInfoHash |
@@ -329,9 +331,11 @@ hash = InfoHash . C.hash | |||
329 | hashlazy :: Lazy.ByteString -> InfoHash | 331 | hashlazy :: Lazy.ByteString -> InfoHash |
330 | hashlazy = InfoHash . C.hashlazy | 332 | hashlazy = InfoHash . C.hashlazy |
331 | 333 | ||
332 | ppInfoHash :: InfoHash -> ByteString | 334 | ppInfoHash :: InfoHash -> Doc |
333 | ppInfoHash = Lazy.toStrict . B.toLazyByteString . | 335 | ppInfoHash = text . BC.unpack . Lazy.toStrict . ppHex . getInfoHash |
334 | foldMap (B.primFixed B.word8HexFixed) . B.unpack . getInfoHash | 336 | |
337 | ppHex :: ByteString -> Lazy.ByteString | ||
338 | ppHex = B.toLazyByteString . foldMap (B.primFixed B.word8HexFixed) . B.unpack | ||
335 | 339 | ||
336 | addHashToURI :: URI -> InfoHash -> URI | 340 | addHashToURI :: URI -> InfoHash -> URI |
337 | addHashToURI uri s = uri { | 341 | addHashToURI uri s = uri { |