summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Torrent.hs8
-rw-r--r--src/Data/Torrent/Layout.hs5
-rw-r--r--src/Data/Torrent/Piece.hs8
3 files changed, 21 insertions, 0 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 7d3917f2..7833c261 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -140,6 +140,10 @@ instance Hashable InfoDict where
140 hashWithSalt = Hashable.hashUsing idInfoHash 140 hashWithSalt = Hashable.hashUsing idInfoHash
141 {-# INLINE hashWithSalt #-} 141 {-# INLINE hashWithSalt #-}
142 142
143-- | Empty info dictionary with zero-length content.
144instance Default InfoDict where
145 def = infoDictionary def def False
146
143-- | Smart constructor: add a info hash to info dictionary. 147-- | Smart constructor: add a info hash to info dictionary.
144infoDictionary :: LayoutInfo -> PieceInfo -> Bool -> InfoDict 148infoDictionary :: LayoutInfo -> PieceInfo -> Bool -> InfoDict
145infoDictionary li pinfo private = InfoDict ih li pinfo private 149infoDictionary li pinfo private = InfoDict ih li pinfo private
@@ -340,6 +344,10 @@ instance Pretty Torrent where
340 "Publisher URL" <:>? ((text . show) <$> tPublisherURL) $$ 344 "Publisher URL" <:>? ((text . show) <$> tPublisherURL) $$
341 "Signature" <:>? ((text . show) <$> tSignature) 345 "Signature" <:>? ((text . show) <$> tSignature)
342 346
347-- | No files, no trackers, no nodes, etc...
348instance Default Torrent where
349 def = nullTorrent def
350
343-- | A simple torrent contains only required fields. 351-- | A simple torrent contains only required fields.
344nullTorrent :: InfoDict -> Torrent 352nullTorrent :: InfoDict -> Torrent
345nullTorrent info = Torrent 353nullTorrent info = Torrent
diff --git a/src/Data/Torrent/Layout.hs b/src/Data/Torrent/Layout.hs
index a4b55b3d..ef8d45eb 100644
--- a/src/Data/Torrent/Layout.hs
+++ b/src/Data/Torrent/Layout.hs
@@ -71,6 +71,7 @@ import Data.BEncode.Types
71import Data.ByteString as BS 71import Data.ByteString as BS
72import Data.ByteString.Base16 as Base16 72import Data.ByteString.Base16 as Base16
73import Data.ByteString.Char8 as BC 73import Data.ByteString.Char8 as BC
74import Data.Default
74import Data.Foldable as F 75import Data.Foldable as F
75import Data.List as L 76import Data.List as L
76import Data.Text as T 77import Data.Text as T
@@ -222,6 +223,10 @@ instance NFData LayoutInfo where
222 rnf SingleFile {..} = () 223 rnf SingleFile {..} = ()
223 rnf MultiFile {..} = rnf liFiles 224 rnf MultiFile {..} = rnf liFiles
224 225
226-- | Empty multifile layout.
227instance Default LayoutInfo where
228 def = MultiFile [] ""
229
225getLayoutInfo :: Get LayoutInfo 230getLayoutInfo :: Get LayoutInfo
226getLayoutInfo = single <|> multi 231getLayoutInfo = single <|> multi
227 where 232 where
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