module Fossyl

Constants

InvalidBencoding

Public Class Methods

dump(object) click to toggle source
# File lib/fossyl.rb, line 4
def self.dump(object)
  case object
  when String, Symbol
    "#{object.length}:#{object}"
  when Integer
    "i#{object}e"
  when Array
    list = object.map {|item| dump(item) }.join
    "l#{list}e"
  when Hash
    hash = object.sort.map {|key, value| dump(key) << dump(value) }.join
    "d#{hash}e"
  end
end
load(string) click to toggle source
# File lib/fossyl.rb, line 19
def self.load(string)
  Fossyl::Parser.new(string.b).parse
end