From 7a6afc239fb21de0aa71f1549e78720a9e923646 Mon Sep 17 00:00:00 2001 From: Jaseem Abid Date: Sat, 18 Apr 2015 15:01:59 +0530 Subject: [PATCH] Fix bdict encode, cleanup blist encode This one took a long time to debug! Need more unit tests --- src/FuncTorrent/Bencode.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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] -- 2.37.2