diff options
Diffstat (limited to 'src/Data/Torrent/Piece.hs')
-rw-r--r-- | src/Data/Torrent/Piece.hs | 17 |
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 | |||
61 | import Data.Text.Encoding as T | 59 | import Data.Text.Encoding as T |
62 | import Data.Typeable | 60 | import Data.Typeable |
63 | import Text.PrettyPrint | 61 | import Text.PrettyPrint |
62 | import Text.PrettyPrint.Class | ||
64 | 63 | ||
65 | import Data.Torrent.Block | 64 | import Data.Torrent.Block |
66 | 65 | ||
@@ -121,10 +120,9 @@ $(deriveJSON (L.map toLower . L.dropWhile isLower) ''Piece) | |||
121 | 120 | ||
122 | instance NFData (Piece a) | 121 | instance NFData (Piece a) |
123 | 122 | ||
124 | -- | Format piece in human readable form. Payload bytes are omitted. | 123 | -- | Payload bytes are omitted. |
125 | ppPiece :: Piece a -> Doc | 124 | instance Pretty (Piece a) where |
126 | ppPiece 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. |
130 | pieceSize :: Piece BL.ByteString -> PieceSize | 128 | pieceSize :: 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. |
196 | ppPieceInfo :: PieceInfo -> Doc | 194 | instance Pretty PieceInfo where |
197 | ppPieceInfo PieceInfo {..} = | 195 | pretty PieceInfo {..} = "Piece size: " <> int piPieceLength |
198 | "Piece size: " <> int piPieceLength | ||
199 | 196 | ||
200 | hashsize :: Int | 197 | hashsize :: Int |
201 | hashsize = 20 | 198 | hashsize = 20 |