Nim bencode library
-
Encode from JSON objects
-
Basic unit tests
-
Tested on Linux
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()