bencoding: A library for encoding and decoding of BEncode data.

[ bsd3, data, library ] [ Propose Tags ]

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

[Skip to Readme]


Manual Flags


Enable development options


Compare performance of this package against AttoBencode in benchmarks


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,,,,,,,,, (info)
Change log ChangeLog
Dependencies attoparsec (>=0.10), base (>=4.9 && <5), bytestring (>=0.10), deepseq (>=1.3), ghc-prim, integer-gmp, mtl, pretty, semigroups (>=0.9), text (>=0.11) [details]
License BSD-3-Clause
Copyright (c) 2013-2018, Sam Truzjan (c) 2018 Sergey Vinokurov
Author Sam Truzjan
Maintainer Sergey Vinokurov <>
Category Data
Home page
Bug tracker
Source repo head: git clone -b master
this: git clone -b master(tag v0.4.5.1)
Uploaded by SergeyVinokurov at 2024-01-01T14:16:36Z
Distributions NixOS:, Stackage:
Reverse Dependencies 5 direct, 0 indirect [details]
Downloads 14490 total (48 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-01-01 [all 1 reports]

Readme for bencoding-

[back to package description]


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



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