From: Ramakrishnan Muthukrishnan Date: Sun, 12 Jul 2015 15:52:30 +0000 (+0530) Subject: move torrentToMetainfo into Metainfo module X-Git-Url: https://git.rkrishnan.org/simplejson/components/com_hotproperty/css/%3C?a=commitdiff_plain;h=3e41cb8ab03b431c096c6bc7461ed9d19e9e252c;p=functorrent.git move torrentToMetainfo into Metainfo module --- diff --git a/src/FuncTorrent.hs b/src/FuncTorrent.hs index 59fe32f..576e6b5 100644 --- a/src/FuncTorrent.hs +++ b/src/FuncTorrent.hs @@ -13,7 +13,7 @@ module FuncTorrent logMessage, logStop, mkInfo, - mkMetaInfo + torrentToMetainfo ) where import FuncTorrent.Bencode diff --git a/src/FuncTorrent/Metainfo.hs b/src/FuncTorrent/Metainfo.hs index 4eece7d..daf008f 100644 --- a/src/FuncTorrent/Metainfo.hs +++ b/src/FuncTorrent/Metainfo.hs @@ -2,7 +2,7 @@ module FuncTorrent.Metainfo (Info(..), Metainfo(..), mkInfo, - mkMetaInfo + torrentToMetainfo ) where import Prelude hiding (lookup) @@ -11,7 +11,7 @@ import Data.Map as M ((!), lookup) import Crypto.Hash.SHA1 (hash) import Data.Maybe (maybeToList) -import FuncTorrent.Bencode (BVal(..), encode, bstrToString, bValToInteger) +import FuncTorrent.Bencode (BVal(..), encode, decode, bstrToString, bValToInteger) -- only single file mode supported for the time being. data Info = Info { pieceLength :: !Integer @@ -80,3 +80,11 @@ getAnnounceList (Just (Blist l)) = map (\s -> case s of _ -> "") l getAnnounceList (Just (Bdict _)) = [] + +torrentToMetainfo :: ByteString -> Either String Metainfo +torrentToMetainfo s = + case (decode s) of + Right d -> + mkMetaInfo d + Left e -> + Left $ show e diff --git a/src/Main.hs b/src/Main.hs index 7ba6d96..f86e32c 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -7,9 +7,8 @@ import System.Environment (getArgs) import System.Exit (exitSuccess) import System.Directory (doesFileExist) -import FuncTorrent.Bencode (decode) import FuncTorrent.Logger (initLogger, logMessage, logStop) -import FuncTorrent.Metainfo (Info(..), Metainfo(..), mkMetaInfo) +import FuncTorrent.Metainfo (Info(..), Metainfo(..), torrentToMetainfo) import FuncTorrent.Peer (handShake, msgLoop) import FuncTorrent.Tracker (peers, getTrackerResponse) @@ -34,14 +33,6 @@ parse [a] = do else error "file does not exist" parse _ = exit -torrentToMetaInfo :: ByteString -> Either String Metainfo -torrentToMetaInfo s = - case (decode s) of - Right d -> - mkMetaInfo d - Left e -> - Left $ show e - main :: IO () main = do args <- getArgs @@ -50,7 +41,7 @@ main = do log "Starting up functorrent" log $ "Parsing arguments " ++ concat args torrentStr <- parse args - case (torrentToMetaInfo torrentStr) of + case (torrentToMetainfo torrentStr) of Right m -> do log "Input File OK" log $ "Downloading file : " ++ name (info m)