Skip to content

maliqq/bencode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bencode

A modern, minimal Ruby implementation of the bencode encoding format with a small command-line interface.

Installation

gem build bencode.gemspec
# gem install ./bencode-0.1.0.gem

Library usage

require "bencode"

payload = Bencode.encode({ "hello" => [1, "world"] })
# => "d5:hellol1e5:worldee"

object = Bencode.decode(payload)
# => {"hello"=>[1, "world"]}

Encoding supports strings, symbols, integers, arrays, and hashes (with string or symbol keys). Dictionary keys are sorted to produce deterministic output. Decoding returns plain Ruby strings, integers, arrays, and hashes.

Command line

The bencode executable can decode bencoded input to pretty-printed JSON or encode JSON into bencode. Input defaults to STDIN and output defaults to STDOUT.

# Decode a torrent file to JSON
bencode --decode --file ./example.torrent

# Encode JSON to bencode, writing the output to a file
cat payload.json | bencode --encode --output payload.bencode

Options:

  • -e, --encode – encode JSON input into bencode
  • -d, --decode – decode bencode input into JSON (default)
  • -f, --file FILE – read input from a file instead of STDIN
  • -o, --output FILE – write output to a file instead of STDOUT
  • -h, --help – show usage information

Development

Run the test suite with:

bundle install
bundle exec rspec

Or using the default rake task:

bundle exec rake

About

parses bittorrent bencoding format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages