bencoding

Build Status

Crystal library for the Bencoding data serialization format

What is bencoding?

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

It contains only four data types, namely:

For more info see the bencoding spec.

Installation

Add this to your application's shard.yml:

dependencies:
  bencoding:
    github: t-richards/bencoding

Usage

require "bencoding"

# Decoding:
Bencoding.decode("d3:foo3:bar3:bazi42ee") # => {"foo" => "bar", "baz" => 42}

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

Contributing

  1. Fork it ( https://github.com/t-richards/bencoding/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors