summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/Piece.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-23 03:37:15 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-23 03:37:15 +0400
commited25a297094b483dce06e14d52ced2f93f6dca41 (patch)
tree3df60d8b30af29345de021f251903a175e78c70c /src/Data/Torrent/Piece.hs
parent708938679954a5d5f9def82e1fa873c19ed662df (diff)
Use pretty-class package
Diffstat (limited to 'src/Data/Torrent/Piece.hs')
-rw-r--r--src/Data/Torrent/Piece.hs17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/Data/Torrent/Piece.hs b/src/Data/Torrent/Piece.hs
index c8727a65..6cff53d6 100644
--- a/src/Data/Torrent/Piece.hs
+++ b/src/Data/Torrent/Piece.hs
@@ -21,13 +21,11 @@ module Data.Torrent.Piece
21 21
22 -- * Piece data 22 -- * Piece data
23 , Piece (..) 23 , Piece (..)
24 , ppPiece
25 , pieceSize 24 , pieceSize
26 , isPiece 25 , isPiece
27 26
28 -- * Piece control 27 -- * Piece control
29 , PieceInfo (..) 28 , PieceInfo (..)
30 , ppPieceInfo
31 , pieceCount 29 , pieceCount
32 30
33 -- * Lens 31 -- * Lens
@@ -61,6 +59,7 @@ import Data.List as L
61import Data.Text.Encoding as T 59import Data.Text.Encoding as T
62import Data.Typeable 60import Data.Typeable
63import Text.PrettyPrint 61import Text.PrettyPrint
62import Text.PrettyPrint.Class
64 63
65import Data.Torrent.Block 64import Data.Torrent.Block
66 65
@@ -121,10 +120,9 @@ $(deriveJSON (L.map toLower . L.dropWhile isLower) ''Piece)
121 120
122instance NFData (Piece a) 121instance NFData (Piece a)
123 122
124-- | Format piece in human readable form. Payload bytes are omitted. 123-- | Payload bytes are omitted.
125ppPiece :: Piece a -> Doc 124instance Pretty (Piece a) where
126ppPiece Piece {..} 125 pretty Piece {..} = "Piece" <+> braces ("index" <+> "=" <+> int pieceIndex)
127 = "Piece" <+> braces ("index" <+> "=" <+> int pieceIndex)
128 126
129-- | Get size of piece in bytes. 127-- | Get size of piece in bytes.
130pieceSize :: Piece BL.ByteString -> PieceSize 128pieceSize :: Piece BL.ByteString -> PieceSize
@@ -192,10 +190,9 @@ instance BEncode PieceInfo where
192 toBEncode = toDict . (`putPieceInfo` endDict) 190 toBEncode = toDict . (`putPieceInfo` endDict)
193 fromBEncode = fromDict getPieceInfo 191 fromBEncode = fromDict getPieceInfo
194 192
195-- | Format piece info in human readable form. Hashes are omitted. 193-- | Hashes are omitted.
196ppPieceInfo :: PieceInfo -> Doc 194instance Pretty PieceInfo where
197ppPieceInfo PieceInfo {..} = 195 pretty PieceInfo {..} = "Piece size: " <> int piPieceLength
198 "Piece size: " <> int piPieceLength
199 196
200hashsize :: Int 197hashsize :: Int
201hashsize = 20 198hashsize = 20