summaryrefslogtreecommitdiff
path: root/src/Data/Torrent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r--src/Data/Torrent.hs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index a746b54c..69461488 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -42,15 +42,19 @@ module Data.Torrent
42 , FileOffset 42 , FileOffset
43 , FileSize 43 , FileSize
44 , FileInfo (..) 44 , FileInfo (..)
45#ifdef VERSION_lens
45 , fileLength 46 , fileLength
46 , filePath 47 , filePath
47 , fileMD5Sum 48 , fileMD5Sum
49#endif
48 50
49 -- ** Layout info 51 -- ** Layout info
50 , LayoutInfo (..) 52 , LayoutInfo (..)
53#ifdef VERSION_lens
51 , singleFile 54 , singleFile
52 , multiFile 55 , multiFile
53 , rootDirName 56 , rootDirName
57#endif
54 , joinFilePath 58 , joinFilePath
55 , isSingleFile 59 , isSingleFile
56 , isMultiFile 60 , isMultiFile
@@ -86,8 +90,10 @@ module Data.Torrent
86 -- ** Piece control 90 -- ** Piece control
87 , HashList (..) 91 , HashList (..)
88 , PieceInfo (..) 92 , PieceInfo (..)
93#ifdef VERSION_lens
89 , pieceLength 94 , pieceLength
90 , pieceHashes 95 , pieceHashes
96#endif
91 , pieceCount 97 , pieceCount
92 98
93 -- ** Validation 99 -- ** Validation
@@ -96,10 +102,12 @@ module Data.Torrent
96 102
97 -- * Info dictionary 103 -- * Info dictionary
98 , InfoDict (..) 104 , InfoDict (..)
105#ifdef VERSION_lens
99 , infohash 106 , infohash
100 , layoutInfo 107 , layoutInfo
101 , pieceInfo 108 , pieceInfo
102 , isPrivate 109 , isPrivate
110#endif
103#ifdef VERSION_bencoding 111#ifdef VERSION_bencoding
104 , infoDictionary 112 , infoDictionary
105#endif 113#endif
@@ -107,6 +115,7 @@ module Data.Torrent
107 -- * Torrent file 115 -- * Torrent file
108 , Torrent(..) 116 , Torrent(..)
109 117
118#ifdef VERSION_lens
110 -- ** Lenses 119 -- ** Lenses
111 , announce 120 , announce
112 , announceList 121 , announceList
@@ -118,6 +127,7 @@ module Data.Torrent
118 , publisher 127 , publisher
119 , publisherURL 128 , publisherURL
120 , signature 129 , signature
130#endif
121 131
122 -- ** Utils 132 -- ** Utils
123 , nullTorrent 133 , nullTorrent
@@ -151,7 +161,7 @@ import Prelude hiding ((<>))
151import Control.Applicative 161import Control.Applicative
152import Control.DeepSeq 162import Control.DeepSeq
153import Control.Exception 163import Control.Exception
154import Control.Lens 164-- import Control.Lens
155import Control.Monad 165import Control.Monad
156import Crypto.Hash 166import Crypto.Hash
157#ifdef VERSION_bencoding 167#ifdef VERSION_bencoding
@@ -368,12 +378,14 @@ data FileInfo a = FileInfo {
368 , Functor, Foldable 378 , Functor, Foldable
369 ) 379 )
370 380
381#ifdef VERSION_lens
371makeLensesFor 382makeLensesFor
372 [ ("fiLength", "fileLength") 383 [ ("fiLength", "fileLength")
373 , ("fiMD5Sum", "fileMD5Sum") 384 , ("fiMD5Sum", "fileMD5Sum")
374 , ("fiName" , "filePath" ) 385 , ("fiName" , "filePath" )
375 ] 386 ]
376 ''FileInfo 387 ''FileInfo
388#endif
377 389
378instance NFData a => NFData (FileInfo a) where 390instance NFData a => NFData (FileInfo a) where
379 rnf FileInfo {..} = rnf fiName 391 rnf FileInfo {..} = rnf fiName
@@ -455,12 +467,14 @@ data LayoutInfo
455 , liDirName :: !BS.ByteString 467 , liDirName :: !BS.ByteString
456 } deriving (Show, Read, Eq, Typeable) 468 } deriving (Show, Read, Eq, Typeable)
457 469
470#ifdef VERSION_lens
458makeLensesFor 471makeLensesFor
459 [ ("liFile" , "singleFile" ) 472 [ ("liFile" , "singleFile" )
460 , ("liFiles" , "multiFile" ) 473 , ("liFiles" , "multiFile" )
461 , ("liDirName", "rootDirName") 474 , ("liDirName", "rootDirName")
462 ] 475 ]
463 ''LayoutInfo 476 ''LayoutInfo
477#endif
464 478
465instance NFData LayoutInfo where 479instance NFData LayoutInfo where
466 rnf SingleFile {..} = () 480 rnf SingleFile {..} = ()
@@ -681,11 +695,13 @@ data PieceInfo = PieceInfo
681 -- ^ Concatenation of all 20-byte SHA1 hash values. 695 -- ^ Concatenation of all 20-byte SHA1 hash values.
682 } deriving (Show, Read, Eq, Typeable) 696 } deriving (Show, Read, Eq, Typeable)
683 697
698#ifdef VERSION_lens
684-- | Number of bytes in each piece. 699-- | Number of bytes in each piece.
685makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo 700makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo
686 701
687-- | Concatenation of all 20-byte SHA1 hash values. 702-- | Concatenation of all 20-byte SHA1 hash values.
688makeLensesFor [("piPieceHashes", "pieceHashes")] ''PieceInfo 703makeLensesFor [("piPieceHashes", "pieceHashes")] ''PieceInfo
704#endif
689 705
690instance NFData PieceInfo where 706instance NFData PieceInfo where
691 rnf (PieceInfo a (HashList b)) = rnf a `seq` rnf b 707 rnf (PieceInfo a (HashList b)) = rnf a `seq` rnf b
@@ -766,6 +782,7 @@ data InfoDict = InfoDict
766 -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html> 782 -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html>
767 } deriving (Show, Read, Eq, Typeable) 783 } deriving (Show, Read, Eq, Typeable)
768 784
785#ifdef VERISON_lens
769makeLensesFor 786makeLensesFor
770 [ ("idInfoHash" , "infohash" ) 787 [ ("idInfoHash" , "infohash" )
771 , ("idLayoutInfo", "layoutInfo") 788 , ("idLayoutInfo", "layoutInfo")
@@ -773,6 +790,7 @@ makeLensesFor
773 , ("idPrivate" , "isPrivate" ) 790 , ("idPrivate" , "isPrivate" )
774 ] 791 ]
775 ''InfoDict 792 ''InfoDict
793#endif
776 794
777instance NFData InfoDict where 795instance NFData InfoDict where
778 rnf InfoDict {..} = rnf idLayoutInfo 796 rnf InfoDict {..} = rnf idLayoutInfo
@@ -884,6 +902,7 @@ data Torrent = Torrent
884 -- encrypted SHA-1 hash of the info dictionary). 902 -- encrypted SHA-1 hash of the info dictionary).
885 } deriving (Show, Eq, Typeable) 903 } deriving (Show, Eq, Typeable)
886 904
905#ifdef VERSION_lens
887makeLensesFor 906makeLensesFor
888 [ ("tAnnounce" , "announce" ) 907 [ ("tAnnounce" , "announce" )
889 , ("tAnnounceList", "announceList") 908 , ("tAnnounceList", "announceList")
@@ -897,6 +916,7 @@ makeLensesFor
897 , ("tSignature" , "signature" ) 916 , ("tSignature" , "signature" )
898 ] 917 ]
899 ''Torrent 918 ''Torrent
919#endif
900 920
901instance NFData Torrent where 921instance NFData Torrent where
902 rnf Torrent {..} = rnf tInfoDict 922 rnf Torrent {..} = rnf tInfoDict