summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-17 04:08:20 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-17 04:08:20 +0400
commit22a3557ed14008a655d20ad216db22134442ed5b (patch)
tree144bfa1beff36f2a6d13a3b15266190704c6fe9e /src
parent36cac7b4646d64c485320f066e6fb6a2a54427d3 (diff)
+ Add a few auxilaru functions.
Diffstat (limited to 'src')
-rw-r--r--src/Data/Torrent.hs7
-rw-r--r--src/Network/BitTorrent.hs7
2 files changed, 13 insertions, 1 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 8e837b56..a1df0034 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -33,7 +33,7 @@ module Data.Torrent
33 33
34 -- * Files layout 34 -- * Files layout
35 , Layout, contentLayout 35 , Layout, contentLayout
36 , contentLength, fileOffset 36 , contentLength, fileCount, fileOffset
37 , pieceCount, blockCount 37 , pieceCount, blockCount
38 , isSingleFile, isMultiFile 38 , isSingleFile, isMultiFile
39 39
@@ -415,6 +415,11 @@ contentLength :: ContentInfo -> Integer
415contentLength SingleFile { ciLength = len } = len 415contentLength SingleFile { ciLength = len } = len
416contentLength MultiFile { ciFiles = tfs } = sum (map fiLength tfs) 416contentLength MultiFile { ciFiles = tfs } = sum (map fiLength tfs)
417 417
418-- | Get count of all files in torrent.
419fileCount :: ContentInfo -> Int
420fileCount SingleFile {..} = 1
421fileCount MultiFile {..} = length ciFiles
422
418-- | Find count of pieces in the torrent. If torrent size is not a 423-- | Find count of pieces in the torrent. If torrent size is not a
419-- multiple of piece size then the count is rounded up. 424-- multiple of piece size then the count is rounded up.
420pieceCount :: ContentInfo -> Int 425pieceCount :: ContentInfo -> Int
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index 8bbd774e..7ae43cec 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -24,6 +24,7 @@ module Network.BitTorrent
24 , getSwarm 24 , getSwarm
25 , getStorage 25 , getStorage
26 , getTorrentInfo 26 , getTorrentInfo
27 , getTorrentInfoStr
27 28
28 -- * Extensions 29 -- * Extensions
29 , Extension 30 , Extension
@@ -37,6 +38,7 @@ import Network.BitTorrent.Sessions.Types
37import Network.BitTorrent.Sessions 38import Network.BitTorrent.Sessions
38import Network.BitTorrent.Extension 39import Network.BitTorrent.Extension
39import Network.BitTorrent.Tracker 40import Network.BitTorrent.Tracker
41import Text.Read
40 42
41-- TODO remove fork from Network.BitTorrent.Exchange 43-- TODO remove fork from Network.BitTorrent.Exchange
42-- TODO make all forks in Internal. 44-- TODO make all forks in Internal.
@@ -61,6 +63,11 @@ addTorrent cs loc @ TorrentLoc {..} = do
61removeTorrent :: ClientSession -> InfoHash -> IO () 63removeTorrent :: ClientSession -> InfoHash -> IO ()
62removeTorrent ses loc = undefined -- atomically $ unregisterTorrent ses loc 64removeTorrent ses loc = undefined -- atomically $ unregisterTorrent ses loc
63 65
66getTorrentInfoStr :: ClientSession -> String -> IO (Maybe Torrent)
67getTorrentInfoStr cs str
68 | Just infohash <- readMaybe str = getTorrentInfo cs infohash
69 | otherwise = return Nothing
70
64{- 71{-
65-- | The same as 'removeTorrrent' torrent, but delete all torrent 72-- | The same as 'removeTorrrent' torrent, but delete all torrent
66-- content files. 73-- content files.