Module: BEncode
- Defined in:
- lib/bencode.rb,
lib/bencode/decode.rb,
lib/bencode/parser.rb
Overview
Support for loading and dumping bencoded data.
See BEncode.load and BEncode.dump.
Defined Under Namespace
Classes: DecodeError, EncodeError, Parser
Constant Summary collapse
- VERSION =
"0.8.2"
Class Method Summary collapse
-
.dump(obj) ⇒ String
Encodes the Ruby object
obj
into a bencoded string. -
.load(str, opts = {}) ⇒ Object
Decodes
str
into a Ruby structure. -
.load_file(path, opts = {}) ⇒ Object
Decodes the file located at
path
.
Class Method Details
.dump(obj) ⇒ String
Encodes the Ruby object obj
into a bencoded string.
10 11 12 |
# File 'lib/bencode/decode.rb', line 10 def self.dump(obj) obj.bencode end |
.load(str, opts = {}) ⇒ Object
Decodes str
into a Ruby structure.
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 |
.load_file(path, opts = {}) ⇒ Object
Decodes the file located at path
.
33 34 35 36 37 |
# File 'lib/bencode/decode.rb', line 33 def self.load_file(path, opts = {}) File.open(path, 'rb') do |io| load(io, opts) end end |