summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/Piece.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-06 06:01:49 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-06 06:01:49 +0400
commitb0d2f2883c9d134b04944d6ec4a4ac15fa516cab (patch)
tree0af3ec4bbcbc5b6e766b549739d13da9294f7413 /src/Data/Torrent/Piece.hs
parent9af46d4e657bce0a343c7ca0dfacad6696bbf503 (diff)
Add Default instance for Torrent datatype
Diffstat (limited to 'src/Data/Torrent/Piece.hs')
-rw-r--r--src/Data/Torrent/Piece.hs8
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
56import Data.ByteString as BS 56import Data.ByteString as BS
57import qualified Data.ByteString.Lazy as BL 57import qualified Data.ByteString.Lazy as BL
58import qualified Data.ByteString.Base64 as Base64 58import qualified Data.ByteString.Base64 as Base64
59import Data.Default
59import Data.Int 60import Data.Int
60import Data.Text.Encoding as T 61import Data.Text.Encoding as T
61import Data.Typeable 62import 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.
175instance 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.
174data PieceInfo = PieceInfo 179data PieceInfo = PieceInfo
175 { piPieceLength :: {-# UNPACK #-} !PieceSize 180 { piPieceLength :: {-# UNPACK #-} !PieceSize
@@ -189,6 +194,9 @@ makeLensesFor [("piPieceHashes", "pieceHashes")] ''PieceInfo
189 194
190instance NFData PieceInfo 195instance NFData PieceInfo
191 196
197instance Default PieceInfo where
198 def = PieceInfo 1 def
199
192instance Lint PieceInfo where 200instance 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