X-Git-Url: https://git.rkrishnan.org/?p=functorrent.git;a=blobdiff_plain;f=src%2FFuncTorrent%2FBencode.hs;fp=src%2FFuncTorrent%2FBencode.hs;h=ac6221119663077f83aeb17757d26a7afc057926;hp=d4eb58c5ac12d0e4f811eb050f95266733b9f262;hb=d80bf91010f9f2f8653c55bb902ec83bf1f034a2;hpb=5180138e2fb80cf8b236784e0be981671506001d diff --git a/src/FuncTorrent/Bencode.hs b/src/FuncTorrent/Bencode.hs index d4eb58c..ac62211 100644 --- a/src/FuncTorrent/Bencode.hs +++ b/src/FuncTorrent/Bencode.hs @@ -23,6 +23,7 @@ module FuncTorrent.Bencode , bValToInteger , bstrToString , decode + , decodeWithLeftOvers , encode ) where @@ -165,6 +166,10 @@ bencVal = Bstr <$> bencStr <|> decode :: ByteString -> Either ParseError BVal decode = parse bencVal "BVal" +decodeWithLeftOvers :: ByteString -> Either ParseError (BVal, ByteString) +decodeWithLeftOvers = parse ((,) <$> bencVal <*> (fmap pack leftOvers)) "BVal with LeftOvers" + where leftOvers = manyTill anyToken eof + -- Encode BVal into a bencoded ByteString. Inverse of decode -- TODO: Use builders and lazy byte string to get O(1) concatenation over O(n)