]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/FuncTorrent/Metainfo.hs
move torrentToMetainfo into Metainfo module
[functorrent.git] / src / FuncTorrent / Metainfo.hs
index 4eece7d5248a0ff257c1f9e02dd9d2e31b924a9e..daf008f25181b5237ca485891e5bb252cde32271 100644 (file)
@@ -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