AttoBencode- Fast Bencode encoding and parsing library

MaintainerFlorian Hartwig <>
Safe HaskellNone






BEncode Types

data BValue Source

The Haskell data type for Bencode values

type Dict = Map ByteString BValueSource

A Bencode dictionary. Dictionaries have ByteString keys and BValue values.

Encoding and Decoding

decode :: FromBencode a => ByteString -> Maybe aSource

Deserialise a bencoded ByteString. If parsing or conversion fails, Nothing is returned.

encode :: ToBencode a => a -> ByteStringSource

Serialise a Bencode value to a (strict) ByteString

class FromBencode a whereSource

A type that can be converted from a BValue. The conversion can fail.

class ToBencode a whereSource

A type that can be converted to a BValue.


toBencode :: a -> BValueSource

Convencience Functions

(.:) :: FromBencode a => Dict -> ByteString -> Maybe aSource

Look up the value corresponding to a (ByteString) key from a dictionary. Returns Nothing if the key is not in the dictionary or if the BValue cannot be converted to the expected type.

dict :: [(ByteString, BValue)] -> BValueSource

Make a BDict from a list of (key, value) tuples.

(.=) :: ToBencode a => ByteString -> a -> (ByteString, BValue)Source

Create a (key, value) tuple from a ByteString key and some bencode-able value. Can be used with the dict function as a convenient way to create BDicts.