Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/rubytorrent/bencoding.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.bencoded?(c) ⇒ Boolean
153 154 155 |
# File 'lib/rubytorrent/bencoding.rb', line 153 def self.bencoded?(c) c == ?d end |
.parse_bencoding(c, s) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/rubytorrent/bencoding.rb', line 157 def self.parse_bencoding(c, s) ret = {} key = nil RubyTorrent::BStream.new(s).each do |x| if key == nil key = x else ret[key] = x key = nil end end raise RubyTorrent::BEncodingError, "no dictionary terminator" unless s.getc == ?e ret end |
Instance Method Details
#to_bencoding ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/rubytorrent/bencoding.rb', line 142 def to_bencoding "d" + keys.sort.map do |k| v = self[k] if v.nil? nil else [k.to_bencoding, v.to_bencoding].join end end.compact.join + "e" end |