A library for encoding and decoding of BEncode data.

Version on this page:
Stackage Nightly 2019-06-12:
Latest on Hackage:

See all snapshots bencoding appears in

BSD-3-Clause licensed by Sam Truzjan
Maintained by Sergey Vinokurov

Module documentation for

There are no documented modules for this package.


BEncode is JSON-like format used in bittorrent protocol but might be used anywhere else.


This package implements fast seamless encoding/decoding to/from bencode format for many native datatypes. To achieve more performance we use bytestring builders and hand optimized attoparsec parser so this library is considered as replacement for BEncode and AttoBencode packages.


Bencode is pretty similar to JSON: it has dictionaries(JSON objects), lists(JSON arrays), strings and integers. However bencode has a few advantages:

  • Compactness: no spaces in between any values — nor lists nor dicts nor anywhere else.
  • Dictionaries always sorted lexicographically by the keys. This allow us to test data on equality without decoding from raw bytestring. Moreover this allow to hash encoded data (this property is heavily used by core bittorrent protocol).
  • All strings prefixed with its length. This simplifies and speed up string parsing.

Hovewer there are some disadvantages comparing with JSON:

  • Bencode is certainly less human readable.
  • Bencode is rarely used, except bittorrent protocol of course.


For documentation see package hackage page.

Build Status

Build Status


Feel free to report bugs and suggestions via issue tracker or the mail.


2019-01-06 Sergey Vinokurov <>

* Fix benchmark build when dependency on AttoBencode is switched off
* Test against GHC 8.6. Make benchmark dependency on AttoBencode disablable

2018-09-18 Sergey Vinokurov <>

* Fix build for GHC 8.0-8.4. Derive Generic instances. Add Semigroup instance.

2013-12-19 Sam Truzjan <>

* Add lookAhead and match functions.

2013-12-16 Sam Truzjan <>

* Override default Monad(fail) method so it is possible
to catch Get monad failures from pure code.

2013-12-14 Sam Truzjan <>

* Override default fixity for operators: previously it
has been impossible to mix bencode Get operators ((<$>!), (<$>?),
(<*>!), (<*>?)) with applicative operators ((<$>), (<*>)).

2013-12-08 Sam Truzjan <>

* Expose parser and builder so it is possible to use
parser incrementally.

2013-10-01 Sam Truzjan <>

* Minor fixes.

2013-10-01 Sam Truzjan <>

* Nothing changed.

2013-10-01 Sam Truzjan <>

* Faster dictionary conversion.

2013-09-28 Sam Truzjan <>

* Rename BEncode to BValue and BEncodable to BEncode.

2013-09-28 Sam Truzjan <>

* Arbitrary length integers. (by specification)

2013-08-26 Sam Truzjan <>

* Added default decoders/encoders using GHC Generics.

2013-06-09 Sam Truzjan <>

* Initial version.
Used by 3 packages:
comments powered byDisqus