diff options
Diffstat (limited to 'src/Data/Torrent/Piece.hs')
-rw-r--r-- | src/Data/Torrent/Piece.hs | 16 |
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 | |||
47 | import Control.DeepSeq | 47 | import Control.DeepSeq |
48 | import Control.Lens | 48 | import Control.Lens |
49 | import qualified Crypto.Hash.SHA1 as SHA1 | 49 | import qualified Crypto.Hash.SHA1 as SHA1 |
50 | import Data.Aeson (ToJSON(..), FromJSON(..), Value(..), withText) | ||
51 | import Data.Aeson.TH | ||
52 | import Data.BEncode | 50 | import Data.BEncode |
53 | import Data.BEncode.Types | 51 | import Data.BEncode.Types |
54 | import Data.Bits | 52 | import Data.Bits |
@@ -63,8 +61,6 @@ import Data.Typeable | |||
63 | import Text.PrettyPrint | 61 | import Text.PrettyPrint |
64 | import Text.PrettyPrint.Class | 62 | import Text.PrettyPrint.Class |
65 | 63 | ||
66 | import Data.Torrent.JSON | ||
67 | |||
68 | 64 | ||
69 | -- TODO add torrent file validation | 65 | -- TODO add torrent file validation |
70 | class Lint a where | 66 | class 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 | |||
144 | instance NFData (Piece a) | 138 | instance NFData (Piece a) |
145 | 139 | ||
146 | -- | Payload bytes are omitted. | 140 | -- | Payload bytes are omitted. |
@@ -163,14 +157,6 @@ hashPiece Piece {..} = SHA1.hashlazy pieceData | |||
163 | newtype HashList = HashList { unHashList :: ByteString } | 157 | newtype 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. | ||
167 | instance ToJSON HashList where | ||
168 | toJSON (HashList bs) = String $ T.decodeUtf8 $ Base64.encode bs | ||
169 | |||
170 | instance 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. |
175 | instance Default HashList where | 161 | instance 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. |
190 | makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo | 174 | makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo |
191 | 175 | ||