Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby bindings for the bencode data serialization format
branch: master

Merge pull request #18 from liudangyi/utf8-encoding

Encode the string as UTF-8
latest commit eef1208fd1
Daniel Schierbeck authored
Failed to load latest commit information.
lib move encoding detect into initialize
test make CI happy
.gitignore Use YARD documentation conventions
.travis.yml Use Ruby 2.1.1 rather than 2.1.0
Gemfile Make the tests work again
LICENSE Add MIT license Add Xinyue Lu as a contributor
Rakefile Replace Jeweler with RakeGem

Ruby bencode binding

This is a simple library for reading and writing bencoded data.

What is bencode?

Bencode is a simple data serialization format used by the popular BitTorrent P2P file sharing system.

It contains only four data types, namely:

  • byte strings
  • integers
  • lists
  • dictionaries


Encoding objects is as simple as calling #bencode on them:

"foo bar".bencode                   # => "7:foo bar"
42.bencode                          # => "i42e"
[1, 2, 3].bencode                   # => "li1ei2ei3ee"
{"foo" => 1, "bar" => -10}.bencode  # => "d3:bari-10e3:fooi1ee"

Decoding a complete data stream is as easy as calling BEncode.load(data).

Decoding a data stream in chunks works as follows:

irb(main):007:0> stream = "d3:foo3:bared3:baz3:quxe")
=> #<BEncode::Parser:0x007fbe6b008c88 @stream=#<StringIO:0x007fbe6b008cd8>>
irb(main):008:0> stream.parse!
=> {"foo"=>"bar"}
irb(main):009:0> stream.parse!
=> {"baz"=>"qux"}


Released under the MIT license.


Something went wrong with that request. Please try again.