diff options
Diffstat (limited to 'src/Data/Torrent/Piece.hs')
-rw-r--r-- | src/Data/Torrent/Piece.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Data/Torrent/Piece.hs b/src/Data/Torrent/Piece.hs index 74a2469a..03335819 100644 --- a/src/Data/Torrent/Piece.hs +++ b/src/Data/Torrent/Piece.hs | |||
@@ -56,6 +56,7 @@ import Data.Bits.Extras | |||
56 | import Data.ByteString as BS | 56 | import Data.ByteString as BS |
57 | import qualified Data.ByteString.Lazy as BL | 57 | import qualified Data.ByteString.Lazy as BL |
58 | import qualified Data.ByteString.Base64 as Base64 | 58 | import qualified Data.ByteString.Base64 as Base64 |
59 | import Data.Default | ||
59 | import Data.Int | 60 | import Data.Int |
60 | import Data.Text.Encoding as T | 61 | import Data.Text.Encoding as T |
61 | import Data.Typeable | 62 | import Data.Typeable |
@@ -170,6 +171,10 @@ instance FromJSON HashList where | |||
170 | parseJSON = withText "HashArray" $ | 171 | parseJSON = withText "HashArray" $ |
171 | either fail (return . HashList) . Base64.decode . T.encodeUtf8 | 172 | either fail (return . HashList) . Base64.decode . T.encodeUtf8 |
172 | 173 | ||
174 | -- | Empty hash list. | ||
175 | instance Default HashList where | ||
176 | def = HashList "" | ||
177 | |||
173 | -- | Part of torrent file used for torrent content validation. | 178 | -- | Part of torrent file used for torrent content validation. |
174 | data PieceInfo = PieceInfo | 179 | data PieceInfo = PieceInfo |
175 | { piPieceLength :: {-# UNPACK #-} !PieceSize | 180 | { piPieceLength :: {-# UNPACK #-} !PieceSize |
@@ -189,6 +194,9 @@ makeLensesFor [("piPieceHashes", "pieceHashes")] ''PieceInfo | |||
189 | 194 | ||
190 | instance NFData PieceInfo | 195 | instance NFData PieceInfo |
191 | 196 | ||
197 | instance Default PieceInfo where | ||
198 | def = PieceInfo 1 def | ||
199 | |||
192 | instance Lint PieceInfo where | 200 | instance Lint PieceInfo where |
193 | lint pinfo @ PieceInfo {..} | 201 | lint pinfo @ PieceInfo {..} |
194 | | BS.length (unHashList piPieceHashes) `rem` hashsize == 0 | 202 | | BS.length (unHashList piPieceHashes) `rem` hashsize == 0 |