From: Jaseem Abid Date: Sat, 18 Apr 2015 09:31:59 +0000 (+0530) Subject: Fix bdict encode, cleanup blist encode X-Git-Url: https://git.rkrishnan.org/components/architecture.txt?a=commitdiff_plain;h=7a6afc239fb21de0aa71f1549e78720a9e923646;p=functorrent.git Fix bdict encode, cleanup blist encode This one took a long time to debug! Need more unit tests --- diff --git a/src/FuncTorrent/Bencode.hs b/src/FuncTorrent/Bencode.hs index 2b641a7..dc149c8 100644 --- a/src/FuncTorrent/Bencode.hs +++ b/src/FuncTorrent/Bencode.hs @@ -159,5 +159,8 @@ decode = parse bencVal "BVal" encode :: BVal -> ByteString encode (Bstr bs) = pack $ show (length bs) ++ ":" ++ unpack bs encode (Bint i) = pack $ "i" ++ show i ++ "e" -encode (Blist xs) = pack $ "l" ++ unpack (concat $ map encode xs) ++ "e" -encode (Bdict d) = concat [concat ["d", encode . Bstr . pack $ k , encode (d ! k) , "e"] | k <- keys d] +encode (Blist xs) = concat ["l", concat $ map encode xs, "e"] +encode (Bdict d) = concat ["d", concat kvlist, "e"] + where + kvlist :: [ByteString] + kvlist = [concat [encode . Bstr . pack $ k , encode (d ! k)] | k <- keys d]