diff options
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r-- | src/Data/Torrent.hs | 17 |
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 @@ | |||
11 | module Data.Torrent | 11 | module 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 | |||
229 | contentLength MultiFile { ciFiles = tfs } = sum (map fiLength tfs) | 230 | contentLength MultiFile { ciFiles = tfs } = sum (map fiLength tfs) |
230 | 231 | ||
231 | pieceCount :: ContentInfo -> Int | 232 | pieceCount :: ContentInfo -> Int |
232 | pieceCount ti = contentLength ti `sizeInBase` ciPieceLength ti | 233 | pieceCount ci = contentLength ci `sizeInBase` ciPieceLength ci |
234 | |||
235 | blockCount :: Int -> ContentInfo -> Int | ||
236 | blockCount 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 | ||
257 | isSingleFile :: ContentInfo -> Bool | ||
258 | isSingleFile SingleFile {} = True | ||
259 | isSingleFile _ = False | ||
260 | |||
261 | isMultiFile :: ContentInfo -> Bool | ||
262 | isMultiFile MultiFile {} = True | ||
263 | isMultiFile _ = False | ||
253 | 264 | ||
254 | 265 | ||
255 | -- | Read and decode a .torrent file. | 266 | -- | Read and decode a .torrent file. |