summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/Piece.hs
diff options
context:
space:
mode:
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