Project

bencoder

0.01
No commit activity in last 3 years
No release in over 3 years
Minimalistic BEncoding gem
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.7.0, ~> 0.7.0
>= 5.4.0, ~> 5.4
 Project Readme

bencoder

Build Status Coverage Status Code Climate Gem Version

Bittorrent encoding in ruby

BEncoder will encode the 4 data types in the specification:

  • Strings
  • Integers
  • Arrays
  • Hashes

Additionally, it will pass symbols as strings, to allow for easier hash convertion.

install with

gem install bencoder

Usage is easy:

BEncoder.encode "herp"
=> "4:herp"

BEncoder.decode "4:herp"
=> "herp"

BEncoder.encode ['what', 'strange', { data: 'I', have: 'here' }, 666]
=> "l4:what7:stranged4:data1:I4:have4:hereei666ee"

BEncoder.decode 'l4:what7:stranged4:data1:I4:have4:hereei666ee'
=> ['what', 'strange', { 'data' => 'I', 'have' => 'here' }, 666]

Since .torrent files are bencode dicts, you can parse them out of the box

BEncoder.decode File.read('sample.torrent')
=> {"announce"=>"udp://tracker.openbittorrent.com:80", "creation date"=>1327049827, "info"=>{"length"=>20, "name"=>"sample.txt", "piece length"=>65536, "pieces"=>"\\\xC5\xE6R\xBE\r\xE6\xF2x\x05\xB3\x04d\xFF\x9B\x00\xF4\x89\xF0\xC9", "private"=>1}}