summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-24 02:28:57 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-24 02:28:57 +0400
commit71806baa0d07f2ea0a92698e26ce79c7c6647a50 (patch)
treeeb80ebedbf0b2965d96c71112263dfae3f2409b9
parentd616ca9030d5420ff43e48c5b06738bec7230fc7 (diff)
~ Add utility functions.
-rw-r--r--src/Data/Torrent.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 47a09cf5..2185f702 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -11,8 +11,9 @@
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 , contentLength, pieceCount 14 , contentLength, pieceCount, blockCount
15 , contentLayout 15 , Layout, contentLayout
16 , isSingleFile, isMultiFile
16 , fromFile 17 , fromFile
17 ) where 18 ) where
18 19
@@ -229,7 +230,10 @@ contentLength SingleFile { ciLength = len } = len
229contentLength MultiFile { ciFiles = tfs } = sum (map fiLength tfs) 230contentLength MultiFile { ciFiles = tfs } = sum (map fiLength tfs)
230 231
231pieceCount :: ContentInfo -> Int 232pieceCount :: ContentInfo -> Int
232pieceCount ti = contentLength ti `sizeInBase` ciPieceLength ti 233pieceCount ci = contentLength ci `sizeInBase` ciPieceLength ci
234
235blockCount :: Int -> ContentInfo -> Int
236blockCount blkSize ci = contentLength ci `sizeInBase` blkSize
233 237
234-- | File layout specifies the order and the size of each file in the storage. 238-- | File layout specifies the order and the size of each file in the storage.
235-- Note that order of files is highly important since we coalesce all 239-- Note that order of files is highly important since we coalesce all
@@ -250,6 +254,13 @@ contentLayout rootPath = filesLayout
250 fl (FileInfo { fiPath = p, fiLength = len }) = (p, fromIntegral len) 254 fl (FileInfo { fiPath = p, fiLength = len }) = (p, fromIntegral len)
251 255
252 256
257isSingleFile :: ContentInfo -> Bool
258isSingleFile SingleFile {} = True
259isSingleFile _ = False
260
261isMultiFile :: ContentInfo -> Bool
262isMultiFile MultiFile {} = True
263isMultiFile _ = False
253 264
254 265
255-- | Read and decode a .torrent file. 266-- | Read and decode a .torrent file.