{-# LANGUAGE OverloadedStrings #-}
module FuncTorrent.Bencode
(BVal(..)
- , bValToBList
- , bValToBytestr
- , bValToInfoDict
, bValToInteger
, bstrToString
, decode
import Data.ByteString (ByteString, length, concat)
import Data.ByteString.Char8 (unpack, pack)
-import Data.Char (isLetter, isNumber, isPrint, isAscii)
+import Data.Char (isLetter, isAscii)
import Data.Map.Strict (Map, fromList, toList)
import Text.ParserCombinators.Parsec
import qualified Text.Parsec.ByteString as ParsecBS
bValToBytestr (Bstr bs) = Just bs
bValToBytestr _ = Nothing
-bValToBList :: BVal -> Maybe [BVal]
-bValToBList (Blist lst) = Just lst
-bValToBList _ = Nothing
-
-bValToInfoDict :: BVal -> Maybe (Map String BVal)
-bValToInfoDict (Bdict dict) = Just dict
-bValToInfoDict _ = Nothing
-
bstrToString :: BVal -> Maybe String
bstrToString bval = unpack <$> bValToBytestr bval
-- is the key "files" present? If so, it is a multi-file torrent
-- if not, it is a single file torrent.
filesIfMulti = lookup "files" m
- (Bint length') = m ! "length"
- md5sum' = Nothing
partialInfo = Info { pieceLength = pieceLength'
, pieces = pieces'
, private = private'
, name = unpack name'
+ , filemeta = []
}
in
case filesIfMulti of