summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Data/Torrent.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 41b78922..e6ed8813 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -11,6 +11,7 @@
11module Data.Torrent 11module Data.Torrent
12 ( module Data.Torrent.InfoHash 12 ( module Data.Torrent.InfoHash
13 , Torrent(..), ContentInfo(..), FileInfo(..) 13 , Torrent(..), ContentInfo(..), FileInfo(..)
14 , contenLength, pieceCount
14 , fromFile 15 , fromFile
15 ) where 16 ) where
16 17
@@ -216,6 +217,18 @@ instance BEncodable FileInfo where
216 217
217 fromBEncode _ = decodingError "FileInfo" 218 fromBEncode _ = decodingError "FileInfo"
218 219
220sizeInBase :: Integer -> Int -> Int
221sizeInBase n b = fromIntegral (n `div` fromIntegral b) + align
222 where
223 align = if n `mod` fromIntegral b == 0 then 0 else 1
224
225contentLength :: ContentInfo -> Integer
226contentLength SingleFile { ciLength = len } = len
227contentLength MultiFile { ciFiles = tfs } = sum (map fiLength tfs)
228
229pieceCount :: ContentInfo -> Int
230pieceCount ti = contentLength ti `sizeInBase` ciPieceLength ti
231
219 232
220-- | Read and decode a .torrent file. 233-- | Read and decode a .torrent file.
221fromFile :: FilePath -> IO (Result Torrent) 234fromFile :: FilePath -> IO (Result Torrent)