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.hs16
1 files changed, 0 insertions, 16 deletions
diff --git a/src/Data/Torrent/Piece.hs b/src/Data/Torrent/Piece.hs
index 03335819..d4b2c399 100644
--- a/src/Data/Torrent/Piece.hs
+++ b/src/Data/Torrent/Piece.hs
@@ -47,8 +47,6 @@ module Data.Torrent.Piece
47import Control.DeepSeq 47import Control.DeepSeq
48import Control.Lens 48import Control.Lens
49import qualified Crypto.Hash.SHA1 as SHA1 49import qualified Crypto.Hash.SHA1 as SHA1
50import Data.Aeson (ToJSON(..), FromJSON(..), Value(..), withText)
51import Data.Aeson.TH
52import Data.BEncode 50import Data.BEncode
53import Data.BEncode.Types 51import Data.BEncode.Types
54import Data.Bits 52import Data.Bits
@@ -63,8 +61,6 @@ import Data.Typeable
63import Text.PrettyPrint 61import Text.PrettyPrint
64import Text.PrettyPrint.Class 62import Text.PrettyPrint.Class
65 63
66import Data.Torrent.JSON
67
68 64
69-- TODO add torrent file validation 65-- TODO add torrent file validation
70class Lint a where 66class Lint a where
@@ -139,8 +135,6 @@ data Piece a = Piece
139 , pieceData :: !a 135 , pieceData :: !a
140 } deriving (Show, Read, Eq, Functor, Typeable) 136 } deriving (Show, Read, Eq, Functor, Typeable)
141 137
142$(deriveJSON omitRecordPrefix ''Piece)
143
144instance NFData (Piece a) 138instance NFData (Piece a)
145 139
146-- | Payload bytes are omitted. 140-- | Payload bytes are omitted.
@@ -163,14 +157,6 @@ hashPiece Piece {..} = SHA1.hashlazy pieceData
163newtype HashList = HashList { unHashList :: ByteString } 157newtype HashList = HashList { unHashList :: ByteString }
164 deriving (Show, Read, Eq, BEncode, Typeable) 158 deriving (Show, Read, Eq, BEncode, Typeable)
165 159
166-- | Represented as base64 encoded JSON string.
167instance ToJSON HashList where
168 toJSON (HashList bs) = String $ T.decodeUtf8 $ Base64.encode bs
169
170instance FromJSON HashList where
171 parseJSON = withText "HashArray" $
172 either fail (return . HashList) . Base64.decode . T.encodeUtf8
173
174-- | Empty hash list. 160-- | Empty hash list.
175instance Default HashList where 161instance Default HashList where
176 def = HashList "" 162 def = HashList ""
@@ -184,8 +170,6 @@ data PieceInfo = PieceInfo
184 -- ^ Concatenation of all 20-byte SHA1 hash values. 170 -- ^ Concatenation of all 20-byte SHA1 hash values.
185 } deriving (Show, Read, Eq, Typeable) 171 } deriving (Show, Read, Eq, Typeable)
186 172
187$(deriveJSON omitRecordPrefix ''PieceInfo)
188
189-- | Number of bytes in each piece. 173-- | Number of bytes in each piece.
190makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo 174makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo
191 175