Method: BEncode.load

Defined in:
lib/bencode/decode.rb

.load(str, opts = {}) ⇒ Object

Decodes str into a Ruby structure.

Parameters:

  • str (String)

    a bencoded string

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :ignore_trailing_junk (Boolean) — default: false

    whether to ignore invalid bencode at the end of str

Returns:

Raises:



21
22
23
24
25
26
# File 'lib/bencode/decode.rb', line 21

def self.load(str, opts = {})
  scanner = BEncode::Parser.new(str)
  obj = scanner.parse!
  raise BEncode::DecodeError unless (opts[:ignore_trailing_junk] || scanner.eos?)
  obj
end