diff options
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r-- | src/Data/Torrent.hs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index 2ebe9374..5971aa9c 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -33,7 +33,8 @@ module Data.Torrent | |||
33 | 33 | ||
34 | -- * Files layout | 34 | -- * Files layout |
35 | , Layout, contentLayout | 35 | , Layout, contentLayout |
36 | , contentLength, pieceCount, blockCount | 36 | , contentLength, fileOffset |
37 | , pieceCount, blockCount | ||
37 | , isSingleFile, isMultiFile | 38 | , isSingleFile, isMultiFile |
38 | 39 | ||
39 | , checkPiece | 40 | , checkPiece |
@@ -54,6 +55,7 @@ module Data.Torrent | |||
54 | -- * Internal | 55 | -- * Internal |
55 | , Data.Torrent.hash | 56 | , Data.Torrent.hash |
56 | , Data.Torrent.hashlazy | 57 | , Data.Torrent.hashlazy |
58 | , layoutOffsets | ||
57 | #endif | 59 | #endif |
58 | ) where | 60 | ) where |
59 | 61 | ||
@@ -449,6 +451,17 @@ contentLayout rootPath = filesLayout | |||
449 | 451 | ||
450 | fl (FileInfo { fiPath = p, fiLength = len }) = (p, fromIntegral len) | 452 | fl (FileInfo { fiPath = p, fiLength = len }) = (p, fromIntegral len) |
451 | 453 | ||
454 | layoutOffsets :: Layout -> Layout | ||
455 | layoutOffsets = go 0 | ||
456 | where | ||
457 | go !_ [] = [] | ||
458 | go !offset ((n, s) : xs) = (n, offset) : go (offset + s) xs | ||
459 | |||
460 | -- | Gives global offset of a content file for a given full path. | ||
461 | fileOffset :: FilePath -> ContentInfo -> Maybe Integer | ||
462 | fileOffset fullPath | ||
463 | = fmap fromIntegral . lookup fullPath . layoutOffsets . contentLayout "" | ||
464 | |||
452 | -- | Test if this is single file torrent. | 465 | -- | Test if this is single file torrent. |
453 | isSingleFile :: ContentInfo -> Bool | 466 | isSingleFile :: ContentInfo -> Bool |
454 | isSingleFile SingleFile {} = True | 467 | isSingleFile SingleFile {} = True |