Sha256: 5d5cdaf31228812c2dd6dc977c76a31a1219cd69cf6a16d59bdc82f415d32fb2

Contents?: true

Size: 500 Bytes

Versions: 2

Compression:

Stored size: 500 Bytes

Contents

module Fossyl
  InvalidBencoding = Class.new(StandardError)

  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

  def self.load(string)
    Fossyl::Parser.new(string.b).parse
  end
end

require "fossyl/parser"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fossyl-0.6.1 lib/fossyl.rb
fossyl-0.6.0 lib/fossyl.rb