bencoding

A library for encoding and decoding of BEncode data.

https://github.com/sergv/bencoding

Version on this page:0.4.5.1@rev:1
LTS Haskell 21.25:0.4.5.4@rev:1
Stackage Nightly 2024-03-28:0.4.5.5
Latest on Hackage:0.4.5.5

See all snapshots bencoding appears in

BSD-3-Clause licensed by Sam Truzjan
Maintained by Sergey Vinokurov
This version can be pinned in stack with:bencoding-0.4.5.1@sha256:bb5702e38f32dcf005763f12aa42f95089dad42584329cb41288547d1905d99f,4688

Module documentation for 0.4.5.1

Synopsis

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

Description

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.

Format

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.

Documentation

For documentation see package hackage page.

Build Status

Build Status

Maintainer [email protected]

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