The bencoding package

[Tags:benchmark, bsd3, library, test]

A library for fast and easy encoding and decoding of BEncode data.

[Skip to Readme]


Versions,,,,,,,,,,, (info)
Change log changelog
Dependencies attoparsec (>=0.10), base (==4.*), bytestring (>=, deepseq (==1.3.*), ghc-prim, mtl, pretty, text (>=0.11) [details]
License BSD3
Copyright (c) 2013, Sam Truzjan
Author Sam Truzjan
Maintainer Sam Truzjan <>
Stability Experimental
Category Data
Home page
Bug tracker
Source repository head: git clone git:// -b master
this: git clone git:// -b master(tag v0.4.0.2)
Uploaded Tue Oct 1 03:43:15 UTC 2013 by SamTruzjan
Distributions NixOS:
Downloads 3076 total (33 in the last 30 days)
0 []
Status Docs available [build log]
Successful builds reported [all 1 reports]




Maintainer's Corner

For package maintainers and hackage trustees

Readme for bencoding

Readme for bencoding-


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 achive 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.