bencode

Bencode serialization/deserialization library

Readme

bencode

Nim bencode library

CircleCI badge badge

  • Encode from JSON objects

  • Basic unit tests

  • Tested on Linux

Installation

nimble install bencode

Usage

import bencode
import tables, json

let decoded = bdecode("d3:bar4:spam3:fooi42ee") # returns BENode

# pretty print
pprint decoded

# encode
assert bencode(33) == "i33e"
assert bencode("foo") == "3:foo"
assert bencode({"bar": "spam", "foo": "42"}.toTable) == "d3:bar4:spam3:foo2:42e"

# encode from JSON
let j = %* {
  "t":"aa", "y":"q", "q":"ping", "a": {
    "id":"abcdefghij0123456789"
  }
}
let encoded = j.bencode()

Contributing

Testing and PRs are welcome.

Need help? Read Nimble
No tagged versions available
License: LGPL 3

Project website Hosted docs